// IController.h
#ifndef ICONTROLLER_H
#define ICONTROLLER_H
#include <QMainWindow>
#include <QSettings>
#include "TQZModel/AccountModel.h"
class IController : public QMainWindow
{
Q_OBJECT
public:
explicit IController(QWidget *parent = nullptr);
virtual ~IController();
protected:
virtual void ResetWindow(double widthScale, double heightScale);
private:
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void paintEvent(QPaintEvent *event);
protected:
QMap<QString, AccountModel>* accountModels(QString settingPath="./config/iniTest.ini");
private:
bool m_moveable;
QPoint z;
QMap<QString, AccountModel>* m_accountModels;
signals:
};
#endif // ICONTROLLER_H
// IController.cpp
#include "IController.h"
#include "ui_mainwindow.h"
#include <QScreen>
#include <QMouseEvent>
#include <QDebug>
#include <QPainter>
#include <QWidget>
#include "IController.h"
#include "TQZModel/AccountModel.h"
#include <QMap>
IController::IController(QWidget *parent) :
QMainWindow(parent),
m_moveable(false),
m_accountModels(nullptr)
{
}
QMap<QString, AccountModel>* IController::accountModels(QString settingPath) {
if (this->m_accountModels == nullptr) {
this->m_accountModels = new QMap<QString, AccountModel>();
QSettings setting(settingPath, QSettings::IniFormat);
QStringList groupList = setting.childGroups();
foreach (const QString &group, groupList) {
QMap<QString, QString> accountMap;
setting.beginGroup(group);
foreach (const QString &key, setting.allKeys()) {
accountMap.insert(key, setting.value(key).toString());
}
setting.endGroup();
this->m_accountModels->insert(group, AccountModel(accountMap));
}
}
return this->m_accountModels;
}
void IController::ResetWindow(double widthScale, double heightScale) {
widthScale = (widthScale > 1) ? 1 : widthScale;
heightScale = (heightScale > 1) ? 1 : heightScale;
QScreen *screen = qApp->primaryScreen();
int screenWidth = screen->size().width();
int screenHeight = screen->size().height();
this->resize(screenWidth * widthScale, screenHeight * heightScale);
this->move(screenWidth * (1 - widthScale) * 0.5, screenHeight * (1 - heightScale) * 0.5);
this->setAttribute(Qt::WA_TranslucentBackground);
}
void IController::paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(QBrush(QColor(50, 50, 50, 248)));
painter.setPen(Qt::transparent);
QRect rect = this->rect();
rect.setWidth(rect.width() - 1);
rect.setHeight(rect.height() - 1);
painter.drawRoundedRect(rect, 6, 6);
QWidget::paintEvent(event);
}
void IController::mousePressEvent(QMouseEvent *event) {
if (event->button() != Qt::LeftButton)
return;
QWidget::mousePressEvent(event);
QPoint y = event->globalPos();
QPoint x = this->geometry().topLeft();
this->z = y - x;
this->m_moveable = true;
}
void IController::mouseMoveEvent(QMouseEvent *event) {
if (!this->m_moveable)
return;
QWidget::mouseMoveEvent(event);
QPoint y = event->globalPos();
QPoint x = y - this->z;
if (this->isMaximized())
return;
this->move(x);
}
void IController::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() != Qt::LeftButton)
return;
QWidget::mouseReleaseEvent(event);
this->m_moveable = false;
}
void IController::mouseDoubleClickEvent(QMouseEvent *event) {
if (event->button() != Qt::RightButton)
return;
QWidget::mouseDoubleClickEvent(event);
}
IController::~IController() {
if (this->m_accountModels != nullptr) {
delete m_accountModels;
this->m_accountModels = nullptr;
}
}
文章来源地址https://www.toymoban.com/news/detail-406190.html
文章来源:https://www.toymoban.com/news/detail-406190.html
到了这里,关于量化交易之QT篇 - IController - 接口类(stable版)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!