You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
7.8 KiB

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "widget/addtradedialog.h"
#include "model/tradetablemodel.h"
#include <QStandardItemModel>
#include "iconhelper.h"
#include "quihelper.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle("mojin");
Init();
InitStyle();
this->installEventFilter(this);
InitTradeTable();
m_UserData.SetManagerType(ManagerType::Ruoyi);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::SetUserInfo(UserInfo user)
{
m_UserInfo = user;
ui->trendsPage->SetUserInfo(user);
}
void MainWindow::LoadTrendsData()
{
ui->trendsPage->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->tradeRecordBtn->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);
// m_pTradesModel->setColumnCount(3);
// m_pTradesModel->setHeaderData(0,Qt::Horizontal,"名称");
// m_pTradesModel->setHeaderData(1,Qt::Horizontal,QDate::currentDate().toString("yyyy-MM-dd"));
// m_pTradesModel->setHeaderData(2,Qt::Horizontal,QDate::currentDate().addDays(-1).toString("yyyy-MM-dd"));
// ui->tradeTableView->setModel(m_pTradesModel);
//日期 星期 名称 操作 价格 数量 当前持仓 操作时涨跌 操作后当日收盘情况 当日操作盈亏情况 当日操作盈亏比例 当日合计盈亏 当日合计盈亏比例 账户净资产 账户当日盈亏 账户当日盈亏比例 盈亏(卖出时计算) 盈亏比例(卖出时计算) 备注
QStringList heanders = QStringList() << tr("date") << tr("week") << tr("name") << tr("operate") << tr("operateprice") << tr("volume")
<< tr("remainig") << tr("operatechange") << tr("close") << tr("operateprofit") << tr("totalprofit")
<< tr("finalprofit") << tr("remark");
m_pTradeStandardModel = new QStandardItemModel(ui->tradeTableView);
m_pTradeStandardModel->setColumnCount(heanders.count());
for(int i = 0 ; i < heanders.count(); i++)
{
m_pTradeStandardModel->setHeaderData(i,Qt::Horizontal,heanders[i]);
}
ui->tradeTableView->setModel(m_pTradeStandardModel);
}
void MainWindow::on_addTrade_pushButton_clicked()
{
AddTradeDialog ad;
ad.setWindowTitle("添加记录");
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->objectName();
QList<QAbstractButton *> tbtns = ui->widgetTop->findChildren<QAbstractButton *>();
foreach (QAbstractButton *btn, tbtns) {
btn->setChecked(btn == b);
}
if (name == "tradeRecordBtn")
{
ui->stackedWidget->setCurrentIndex(0);
} else if (name == "trendsBtn")
{
ui->stackedWidget->setCurrentIndex(1);
} else if (name == "limitBtn")
{
ui->stackedWidget->setCurrentIndex(2);
} else if (name == "newRecordBtn")
{
ui->stackedWidget->setCurrentIndex(3);
} else if (name == "logouBtn")
{
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();
}
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
QWidget *w = (QWidget *)watched;
if(w->property("form") != "title")
{
return QObject::eventFilter(watched, event);
}
if (!w->property("canMove").toBool())
{
return QObject::eventFilter(watched, event);
}
static QPoint mousePoint;
static bool mousePressed = false;
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->type() == QEvent::MouseButtonPress) {
if (mouseEvent->button() == Qt::LeftButton) {
mousePressed = true;
mousePoint = mouseEvent->globalPos() - this->pos();
}
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
mousePressed = false;
} else if (mouseEvent->type() == QEvent::MouseMove) {
if (mousePressed) {
this->move(mouseEvent->globalPos() - mousePoint);
return true;
}
}
else if (event->type() == QEvent::MouseButtonDblClick) {
on_btnMenu_Max_clicked();
}
return QObject::eventFilter(watched, event);
}