fix: 主体mainwindow改造

master
laixingyu 3 years ago
parent 727da63225
commit fb7e2f0acc

@ -4,6 +4,8 @@
#include "widget/addtradedialog.h" #include "widget/addtradedialog.h"
#include "model/tradetablemodel.h" #include "model/tradetablemodel.h"
#include <QStandardItemModel> #include <QStandardItemModel>
#include "iconhelper.h"
#include "quihelper.h"
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@ -11,6 +13,9 @@ MainWindow::MainWindow(QWidget *parent)
{ {
ui->setupUi(this); ui->setupUi(this);
this->setWindowTitle("mojin"); this->setWindowTitle("mojin");
Init();
InitStyle();
this->installEventFilter(this);
InitTradeTable(); InitTradeTable();
m_UserData.SetManagerType(ManagerType::Ruoyi); m_UserData.SetManagerType(ManagerType::Ruoyi);
} }
@ -31,6 +36,70 @@ void MainWindow::LoadTrendsData()
ui->trends->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<QAbstractButton *> tbtns = ui->widgetTop->findChildren<QAbstractButton *>();
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() void MainWindow::InitTradeTable()
{ {
// m_pTradesModel = new TradeTableModel(ui->tradeTableView); // m_pTradesModel = new TradeTableModel(ui->tradeTableView);
@ -63,3 +132,85 @@ void MainWindow::on_addTrade_pushButton_clicked()
ad.exec(); 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<QAbstractButton *> tbtns = ui->widgetTop->findChildren<QAbstractButton *>();
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();
}

@ -23,11 +23,27 @@ public:
void SetUserData(); void SetUserData();
void LoadTrendsData(); void LoadTrendsData();
protected:
bool eventFilter(QObject *watched, QEvent *event);
private: private:
void InitTradeTable(); 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: private slots:
void on_addTrade_pushButton_clicked(); void on_addTrade_pushButton_clicked();
void on_btnMenu_Min_clicked();
void on_btnMenu_Max_clicked();
void on_btnMenu_Close_clicked();
void buttonClick();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
@ -35,5 +51,12 @@ private:
UserData m_UserData; UserData m_UserData;
// TradeTableModel* m_pTradesModel; // TradeTableModel* m_pTradesModel;
QStandardItemModel* m_pTradeStandardModel; QStandardItemModel* m_pTradeStandardModel;
//根据QSS样式获取对应颜色值
QString borderColor;
QString normalBgColor;
QString darkBgColor;
QString normalTextColor;
QString darkTextColor;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

@ -14,148 +14,437 @@
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout"> <widget class="QWidget" name="widgetTitle" native="true">
<item> <property name="geometry">
<widget class="QTabWidget" name="tabWidget"> <rect>
<property name="currentIndex"> <x>0</x>
<number>0</number> <y>0</y>
</property> <width>1440</width>
<widget class="TrendsWidget" name="trends"> <height>65</height>
<attribute name="title"> </rect>
<string>动量趋势</string> </property>
</attribute> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labIco">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
<widget class="QWidget" name="newrecord"> </item>
<attribute name="title"> <item>
<string>新高新低</string> <widget class="QLabel" name="labTitle">
</attribute> <property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget> </widget>
<widget class="QWidget" name="limit"> </item>
<attribute name="title"> <item>
<string> 涨跌停板</string> <widget class="QWidget" name="widgetTop" native="true">
</attribute> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="btnMain">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>交易记录</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/image/main_main.png</normaloff>:/image/main_main.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnConfig">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>动量趋势</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/image/main_config.png</normaloff>:/image/main_config.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnData">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>涨跌停板</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/image/main_data.png</normaloff>:/image/main_data.png</iconset>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnHelp">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>新高新低</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/image/main_person.png</normaloff>:/image/main_person.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnExit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>用户退出</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/image/main_exit.png</normaloff>:/image/main_exit.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
</layout>
</widget> </widget>
<widget class="QWidget" name="trading"> </item>
<attribute name="title"> <item>
<string>交易记录</string> <spacer name="horizontalSpacer_2">
</attribute> <property name="orientation">
<layout class="QVBoxLayout" name="verticalLayout_2"> <enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="widgetMenu" native="true">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="1" column="1" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="btnMenu_Min">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>最小化</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="btnMenu_Close">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>关闭</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="btnMenu_Max">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QStackedWidget" name="stackedWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>70</y>
<width>1440</width>
<height>830</height>
</rect>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QRadioButton" name="radioButton">
<property name="text">
<string>周</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_2">
<property name="text">
<string>月</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <widget class="QRadioButton" name="radioButton_3">
<property name="text">
<string> 季</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_4">
<property name="text">
<string>年</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_5">
<property name="text">
<string> 所有日期</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QRadioButton" name="radioButton"> <widget class="QRadioButton" name="radioButton_6">
<property name="text"> <property name="text">
<string>周</string> <string>自定</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioButton_2"> <widget class="QDateEdit" name="dateEdit"/>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>月</string> <string></string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioButton_3"> <widget class="QDateEdit" name="dateEdit_2"/>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text"> <property name="text">
<string> 季</string> <string>确定</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QRadioButton" name="radioButton_4"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>年</string> <string>当前日期区间</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioButton_5"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string> 所有日期</string> <string>20231209-20231209</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <spacer name="horizontalSpacer">
<item> <property name="orientation">
<widget class="QRadioButton" name="radioButton_6"> <enum>Qt::Horizontal</enum>
<property name="text"> </property>
<string>自定</string> <property name="sizeHint" stdset="0">
</property> <size>
</widget> <width>40</width>
</item> <height>20</height>
<item> </size>
<widget class="QDateEdit" name="dateEdit"/> </property>
</item> </spacer>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string> 至</string>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="dateEdit_2"/>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>确定</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QPushButton" name="addTrade_pushButton">
<item> <property name="text">
<widget class="QLabel" name="label_2"> <string> 添加记录</string>
<property name="text"> </property>
<string>当前日期区间</string> </widget>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>20231209-20231209</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addTrade_pushButton">
<property name="text">
<string> 添加记录</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QTableView" name="tradeTableView"/>
</item>
</layout> </layout>
</widget> </item>
</widget> <item>
</item> <widget class="QTableView" name="tradeTableView"/>
</layout> </item>
</layout>
</widget>
<widget class="TrendsWidget" name="trends"/>
</widget>
</widget> </widget>
<action name="AddTrading"> <action name="AddTrading">
<property name="text"> <property name="text">

@ -272,6 +272,9 @@
<property name="text"> <property name="text">
<string>1qazse42W3</string> <string>1qazse42W3</string>
</property> </property>
<property name="echoMode">
<enum>QLineEdit::PasswordEchoOnEdit</enum>
</property>
<property name="placeholderText"> <property name="placeholderText">
<string>Password</string> <string>Password</string>
</property> </property>

@ -30,41 +30,41 @@ void TrendsWidget::SetUserInfo(UserInfo user)
void TrendsWidget::LoadTrendsData() void TrendsWidget::LoadTrendsData()
{ {
QList<QList<QString> > trends = m_UserData.GetTrends(QDate(),m_UserInfo.token); QList<QList<QString> > trends = m_UserData.GetTrends(QDate(),m_UserInfo.token);
int rowCount = trends.count(); // int rowCount = trends.count();
int columnCount = 0; // int columnCount = 0;
//更新到tableview中 // //更新到tableview中
if(rowCount > 2) // if(rowCount > 2)
{ // {
model->insertRow(0); // model->insertRow(0);
qDebug() << __FUNCTION__ << " trends[0]: " << trends[0]; // qDebug() << __FUNCTION__ << " trends[0]: " << trends[0];
QList<QString> columns = trends[0]; // QList<QString> columns = trends[0];
columnCount = columns.count(); // columnCount = columns.count();
for (int column = 0; column < columnCount; ++column) { // for (int column = 0; column < columnCount; ++column) {
QStandardItem *item = new QStandardItem(columns[column]); // QStandardItem *item = new QStandardItem(columns[column]);
model->setItem(0, column, item); // model->setItem(0, column, item);
} // }
} // }
qDebug() << __FUNCTION__ << " trends[1]: " <<trends[1]; // qDebug() << __FUNCTION__ << " trends[1]: " <<trends[1];
qDebug() << __FUNCTION__ << " trends[2]: " <<trends[2]; // qDebug() << __FUNCTION__ << " trends[2]: " <<trends[2];
qDebug() << __FUNCTION__ << " trends[3]: " <<trends[3]; // qDebug() << __FUNCTION__ << " trends[3]: " <<trends[3];
rowCount = trends[1].count(); // rowCount = trends[1].count();
QList<QString> row1List = trends[1]; // QList<QString> row1List = trends[1];
qDebug() << __FUNCTION__ << trends[1]; // qDebug() << __FUNCTION__ << trends[1];
for(int row = 1 ; row < rowCount; row++) // for(int row = 1 ; row < rowCount; row++)
{ // {
qDebug() << __FUNCTION__ << row << trends[1][row]; // qDebug() << __FUNCTION__ << row << trends[1][row];
model->insertRow(row); // model->insertRow(row);
QStandardItem *item = new QStandardItem(trends[1][row]); // QStandardItem *item = new QStandardItem(trends[1][row]);
model->setItem(row, 0, item); // model->setItem(row, 0, item);
} // }
for(int row = 2 ; row < rowCount; row++) // for(int row = 2 ; row < rowCount; row++)
{ // {
for(int col = 0 ; col < columnCount; col++) // for(int col = 0 ; col < columnCount; col++)
{ // {
QStandardItem *item = new QStandardItem(trends[row][col]); // QStandardItem *item = new QStandardItem(trends[row][col]);
model->setItem(row, col+1, item); // model->setItem(row, col+1, item);
} // }
} // }
} }

Loading…
Cancel
Save