diff --git a/mainwindow.cpp b/mainwindow.cpp index 6b8a652..3a53ebe 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,6 +4,8 @@ #include "widget/addtradedialog.h" #include "model/tradetablemodel.h" #include +#include "iconhelper.h" +#include "quihelper.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -11,6 +13,9 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); this->setWindowTitle("mojin"); + Init(); + InitStyle(); + this->installEventFilter(this); InitTradeTable(); m_UserData.SetManagerType(ManagerType::Ruoyi); } @@ -31,6 +36,70 @@ void MainWindow::LoadTrendsData() ui->trends->LoadTrendsData(); } +void MainWindow::Init() +{ + //设置无边框 + QUIHelper::setFramelessForm(this); + //设置图标 + IconHelper::setIcon(ui->labIco, 0xf073, 30); + IconHelper::setIcon(ui->btnMenu_Min, 0xf068); + IconHelper::setIcon(ui->btnMenu_Max, 0xf067); + IconHelper::setIcon(ui->btnMenu_Close, 0xf00d); + + //ui->widgetMenu->setVisible(false); + ui->widgetTitle->setProperty("form", "title"); + ui->widgetTitle->setProperty("canMove",true); + //关联事件过滤器用于双击放大 + ui->widgetTitle->installEventFilter(this); + ui->widgetTop->setProperty("nav", "top"); + + QFont font; + font.setPixelSize(25); + ui->labTitle->setFont(font); + ui->labTitle->setText(tr("mojin")); + this->setWindowTitle(ui->labTitle->text()); + + QSize icoSize(32, 32); + int icoWidth = 85; + //设置顶部导航按钮 + QList tbtns = ui->widgetTop->findChildren(); + foreach (QAbstractButton *btn, tbtns) + { + btn->setIconSize(icoSize); + btn->setMinimumWidth(icoWidth); + btn->setCheckable(true); + connect(btn, SIGNAL(clicked()), this, SLOT(buttonClick())); + } + + ui->btnMain->click(); +} + +void MainWindow::InitStyle() +{ + //加载样式表 + QString qss; + QFile file(":/qss/blacksoft.css"); + if (file.open(QFile::ReadOnly)) { + qss = QLatin1String(file.readAll()); + QString paletteColor = qss.mid(20, 7); + qApp->setPalette(QPalette(paletteColor)); + qApp->setStyleSheet(qss); + file.close(); + } + + //先从样式表中取出对应的颜色 + QString textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor; + getQssColor(qss, textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor); + + //将对应颜色设置到控件 + this->borderColor = highColor; + this->normalBgColor = normalColorStart; + this->darkBgColor = panelColor; + this->normalTextColor = textColor; + this->darkTextColor = normalTextColor; +} + + void MainWindow::InitTradeTable() { // m_pTradesModel = new TradeTableModel(ui->tradeTableView); @@ -63,3 +132,85 @@ void MainWindow::on_addTrade_pushButton_clicked() ad.exec(); } +void MainWindow::getQssColor(const QString &qss, const QString &flag, QString &color) +{ + int index = qss.indexOf(flag); + if (index >= 0) { + color = qss.mid(index + flag.length(), 7); + } + //qDebug() << TIMEMS << flag << color; +} + +bool MainWindow::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == ui->widgetTitle) { + if (event->type() == QEvent::MouseButtonDblClick) { + on_btnMenu_Max_clicked(); + } + } + return QWidget::eventFilter(watched, event); +} + +void MainWindow::getQssColor(const QString &qss, QString &textColor, QString &panelColor, + QString &borderColor, QString &normalColorStart, QString &normalColorEnd, + QString &darkColorStart, QString &darkColorEnd, QString &highColor) +{ + getQssColor(qss, "TextColor:", textColor); + getQssColor(qss, "PanelColor:", panelColor); + getQssColor(qss, "BorderColor:", borderColor); + getQssColor(qss, "NormalColorStart:", normalColorStart); + getQssColor(qss, "NormalColorEnd:", normalColorEnd); + getQssColor(qss, "DarkColorStart:", darkColorStart); + getQssColor(qss, "DarkColorEnd:", darkColorEnd); + getQssColor(qss, "HighColor:", highColor); +} + +void MainWindow::buttonClick() +{ + QAbstractButton *b = (QAbstractButton *)sender(); + QString name = b->text(); + + QList tbtns = ui->widgetTop->findChildren(); + foreach (QAbstractButton *btn, tbtns) { + btn->setChecked(btn == b); + } + + if (name == "交易记录") { + ui->stackedWidget->setCurrentIndex(0); + } else if (name == "动量趋势") { + ui->stackedWidget->setCurrentIndex(1); + } else if (name == "ddd") { + ui->stackedWidget->setCurrentIndex(0); + } else if (name == "vvv") { + ui->stackedWidget->setCurrentIndex(1); + } else if (name == "aaa") { + exit(0); + } +} + +void MainWindow::on_btnMenu_Min_clicked() +{ + showMinimized(); +} + +void MainWindow::on_btnMenu_Max_clicked() +{ + static bool max = false; + static QRect location = this->geometry(); + + if (max) { + this->setGeometry(location); + } else { + location = this->geometry(); + this->setGeometry(QUIHelper::getScreenRect()); + } + + this->setProperty("canMove", max); + max = !max; +} + +void MainWindow::on_btnMenu_Close_clicked() +{ + close(); +} + diff --git a/mainwindow.h b/mainwindow.h index 8e72c18..00d62d2 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -23,11 +23,27 @@ public: void SetUserData(); void LoadTrendsData(); +protected: + bool eventFilter(QObject *watched, QEvent *event); + private: void InitTradeTable(); + void Init(); + void InitStyle(); + + void getQssColor(const QString &qss, const QString &flag, QString &color); + void getQssColor(const QString &qss, QString &textColor, + QString &panelColor, QString &borderColor, + QString &normalColorStart, QString &normalColorEnd, + QString &darkColorStart, QString &darkColorEnd, + QString &highColor); private slots: void on_addTrade_pushButton_clicked(); + void on_btnMenu_Min_clicked(); + void on_btnMenu_Max_clicked(); + void on_btnMenu_Close_clicked(); + void buttonClick(); private: Ui::MainWindow *ui; @@ -35,5 +51,12 @@ private: UserData m_UserData; // TradeTableModel* m_pTradesModel; QStandardItemModel* m_pTradeStandardModel; + + //根据QSS样式获取对应颜色值 + QString borderColor; + QString normalBgColor; + QString darkBgColor; + QString normalTextColor; + QString darkTextColor; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index f5f9dfe..13cc482 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -14,148 +14,437 @@ MainWindow - - - - - 0 - - - - 动量趋势 - + + + + 0 + 0 + 1440 + 65 + + + + + 0 + 0 + + + + + 10 + + + 10 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::AlignCenter + - - - 新高新低 - + + + + + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + - - - 涨跌停板 - + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 交易记录 + + + + :/image/main_main.png:/image/main_main.png + + + Qt::ToolButtonTextUnderIcon + + + + + + + + 0 + 0 + + + + 动量趋势 + + + + :/image/main_config.png:/image/main_config.png + + + Qt::ToolButtonTextUnderIcon + + + + + + + + 0 + 0 + + + + 涨跌停板 + + + + :/image/main_data.png:/image/main_data.png + + + false + + + Qt::ToolButtonTextUnderIcon + + + + + + + + 0 + 0 + + + + + + + 新高新低 + + + + :/image/main_person.png:/image/main_person.png + + + Qt::ToolButtonTextUnderIcon + + + + + + + + 0 + 0 + + + + + + + 用户退出 + + + + :/image/main_exit.png:/image/main_exit.png + + + Qt::ToolButtonTextUnderIcon + + + + - - - 交易记录 - - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + ArrowCursor + + + Qt::NoFocus + + + 最小化 + + + + + + + + + + + 0 + 0 + + + + ArrowCursor + + + Qt::NoFocus + + + 关闭 + + + + + + + + + + + 0 + 0 + + + + Qt::NoFocus + + + + + + + + + + + + + + + 0 + 70 + 1440 + 830 + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + 所有日期 + + + + + - + - + 自定 - + + + + - + - + + + + - + 确定 + + + + - + - + 当前日期区间 - + - 所有日期 + 20231209-20231209 - - - - - 自定 - - - - - - - - - - - - - - - - - - - - 确定 - - - - + + + Qt::Horizontal + + + + 40 + 20 + + + - - - - - 当前日期区间 - - - - - - - 20231209-20231209 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 添加记录 - - - - + + + 添加记录 + + - - - - - - - + + + + + + + + diff --git a/widget/logindialog.ui b/widget/logindialog.ui index 1fd4ea0..0da33f9 100644 --- a/widget/logindialog.ui +++ b/widget/logindialog.ui @@ -272,6 +272,9 @@ 1qazse42W3 + + QLineEdit::PasswordEchoOnEdit + Password diff --git a/widget/trendswidget.cpp b/widget/trendswidget.cpp index fd218df..72fcbee 100644 --- a/widget/trendswidget.cpp +++ b/widget/trendswidget.cpp @@ -30,41 +30,41 @@ void TrendsWidget::SetUserInfo(UserInfo user) void TrendsWidget::LoadTrendsData() { QList > trends = m_UserData.GetTrends(QDate(),m_UserInfo.token); - int rowCount = trends.count(); - int columnCount = 0; - //更新到tableview中 - if(rowCount > 2) - { - model->insertRow(0); - qDebug() << __FUNCTION__ << " trends[0]: " << trends[0]; - QList columns = trends[0]; - columnCount = columns.count(); - for (int column = 0; column < columnCount; ++column) { - QStandardItem *item = new QStandardItem(columns[column]); - model->setItem(0, column, item); - } - } - qDebug() << __FUNCTION__ << " trends[1]: " < row1List = trends[1]; - qDebug() << __FUNCTION__ << trends[1]; - for(int row = 1 ; row < rowCount; row++) - { - qDebug() << __FUNCTION__ << row << trends[1][row]; - model->insertRow(row); - QStandardItem *item = new QStandardItem(trends[1][row]); - model->setItem(row, 0, item); +// int rowCount = trends.count(); +// int columnCount = 0; +// //更新到tableview中 +// if(rowCount > 2) +// { +// model->insertRow(0); +// qDebug() << __FUNCTION__ << " trends[0]: " << trends[0]; +// QList columns = trends[0]; +// columnCount = columns.count(); +// for (int column = 0; column < columnCount; ++column) { +// QStandardItem *item = new QStandardItem(columns[column]); +// model->setItem(0, column, item); +// } +// } +// qDebug() << __FUNCTION__ << " trends[1]: " < row1List = trends[1]; +// qDebug() << __FUNCTION__ << trends[1]; +// for(int row = 1 ; row < rowCount; row++) +// { +// qDebug() << __FUNCTION__ << row << trends[1][row]; +// model->insertRow(row); +// QStandardItem *item = new QStandardItem(trends[1][row]); +// model->setItem(row, 0, item); - } - for(int row = 2 ; row < rowCount; row++) - { - for(int col = 0 ; col < columnCount; col++) - { - QStandardItem *item = new QStandardItem(trends[row][col]); - model->setItem(row, col+1, item); +// } +// for(int row = 2 ; row < rowCount; row++) +// { +// for(int col = 0 ; col < columnCount; col++) +// { +// QStandardItem *item = new QStandardItem(trends[row][col]); +// model->setItem(row, col+1, item); - } - } +// } +// } }