#pragma execution_character_set('utf-8')

#include 'RobotUI.h' #include #include 'ConsoleWidget.h' #include 'PlayerDataWidget.h' #include 'SettingWidget.h' #include 'RewardSettingWidget.h' #include 'BroadcastWidget.h' #include 'appconfig.h' #include 'rewardconfig.h' #include 'boardcast1config.h' #include 'boardcast2config.h' #include 'sqliteutil.h' #include 'networkutil.h' #include 'peifulog.h'

RobotUI::RobotUI(QWidget* parent) : QMainWindow(parent) , _bLeftSideBarShrinked(false) { ui.setupUi(this);

// 设置无边框
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
this->setAttribute(Qt::WA_TranslucentBackground);
//this->setAttribute(Qt::WA_NoSystemBackground);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);


this->setMouseTracking(true);
ui.centralWidget->setMouseTracking(true);
ui.widgetRight->setMouseTracking(true);
ui.stackedWidgetMain->setMouseTracking(true);

ui.stackedWidgetMain->removeWidget(ui.stackedWidgetMain->widget(0));
ui.stackedWidgetMain->removeWidget(ui.stackedWidgetMain->widget(0));

ui.stackedWidgetMain->addWidget(new ConsoleWidget());
ui.stackedWidgetMain->addWidget(new PlayerDataWidget());
ui.stackedWidgetMain->addWidget(new SettingWidget());
ui.stackedWidgetMain->addWidget(new RewardSettingWidget());
ui.stackedWidgetMain->addWidget(new BroadcastWidget());
ui.stackedWidgetMain->setCurrentIndex(0);

connect(ui.pushButton_console, SIGNAL(clicked()), this, SLOT(slotConsoleWidget()));
connect(ui.pushButton_playerdata, SIGNAL(clicked()), this, SLOT(slotPlayerdataWidget()));
connect(ui.pushButton_programsetting, SIGNAL(clicked()), this, SLOT(slotProgramsettingWidget()));
connect(ui.pushButton_rewardsetting, SIGNAL(clicked()), this, SLOT(slotRewardsettingWidget()));
connect(ui.pushButton_broadcast, SIGNAL(clicked()), this, SLOT(slotBroadcastWidget()));

connect(ui.pushButton_min, SIGNAL(clicked()), this, SLOT(slotMinimizedApp()));
connect(ui.pushButton_max, SIGNAL(clicked()), this, SLOT(slotMaximizedApp()));
connect(ui.pushButton_close, SIGNAL(clicked()), this, SLOT(slotCloseApp()));

connect(ui.pushButton_shrink, SIGNAL(clicked()), this, SLOT(slotShrinkLeftSideBar()));

}

RobotUI::~RobotUI() { delete PeifuLogs::getInstance(); delete RewardConfigs::getInstance(); delete NetWorkUtil::getInstance(); delete AppConfig::getInstance(); delete Boardcast1Config::getInstance(); delete Boardcast2Config::getInstance(); delete SqliteUtil::getInstance();

}

void RobotUI::slotConsoleWidget() { ui.stackedWidgetMain->setCurrentIndex(0);

unCheckedAllButton();
ui.pushButton_console->setChecked(true);

}

void RobotUI::slotPlayerdataWidget() { ui.stackedWidgetMain->setCurrentIndex(1);

unCheckedAllButton();
ui.pushButton_playerdata->setChecked(true);

}

void RobotUI::slotProgramsettingWidget() { ui.stackedWidgetMain->setCurrentIndex(2);

unCheckedAllButton();
ui.pushButton_programsetting->setChecked(true);

}

void RobotUI::slotRewardsettingWidget() { ui.stackedWidgetMain->setCurrentIndex(3);

unCheckedAllButton();
ui.pushButton_rewardsetting->setChecked(true);

}

void RobotUI::slotBroadcastWidget() { ui.stackedWidgetMain->setCurrentIndex(4);

unCheckedAllButton();
ui.pushButton_broadcast->setChecked(true);

}

void RobotUI::slotMinimizedApp() { this->showMinimized(); }

void RobotUI::slotMaximizedApp() { if (!this->isMaximized()) { this->showMaximized(); } else { this->showNormal(); } }

void RobotUI::slotCloseApp() { this->close(); }

void RobotUI::unCheckedAllButton() { ui.pushButton_console->setChecked(false); ui.pushButton_playerdata->setChecked(false); ui.pushButton_programsetting->setChecked(false); ui.pushButton_rewardsetting->setChecked(false); ui.pushButton_broadcast->setChecked(false); }

void RobotUI::slotShrinkLeftSideBar() { if (_bLeftSideBarShrinked == false) { ui.pushButton_console->setText(''); ui.pushButton_playerdata->setText(''); ui.pushButton_programsetting->setText(''); ui.pushButton_rewardsetting->setText(''); ui.pushButton_broadcast->setText(''); ui.pushButton_feedback->setText(''); ui.pushButton_aboutus->setText(''); ui.pushButton_shrink->setText('');

	ui.widgetLeft->setMaximumWidth(60);
	_bLeftSideBarShrinked = true;

	//ui.pushButton_shrink->setIcon(QIcon(':/RobotUI/Resources/顶部.svg'));
}
else
{
	ui.pushButton_console->setText('        控制台');
	ui.pushButton_playerdata->setText('        玩家数据');
	ui.pushButton_programsetting->setText('        程序设置');
	ui.pushButton_rewardsetting->setText('        赔率-奖励设置');
	ui.pushButton_broadcast->setText('        播报格式-反水');
	ui.pushButton_feedback->setText('        建议反馈');
	ui.pushButton_aboutus->setText('        关于我们');
	ui.pushButton_shrink->setText('    剩余时间:6天18小时26分');

	//QString stylesheet = 'QPushButton{'		//	'background-color:rgb(26, 30, 35);'		//	'color:rgb(150, 157, 171);'		//	'border-radius:10px;'		//	'padding-right:10px;'		//	'}'		//	'QPushButton:hover, QPushButton:checked{'		//	'background-color: rgb(44, 49, 59);'		//	'border-top-left-radius:10px;'		//	'border-bottom-left-radius:10px;'		//	'border-top- right-radius:0px;'		//	'border-bottom-right-radius:0px;'		//	'}';

	//ui.pushButton_console->setStyleSheet(stylesheet);
	//ui.pushButton_playerdata->setStyleSheet(stylesheet);
	//ui.pushButton_programsetting->setStyleSheet(stylesheet);
	//ui.pushButton_rewardsetting->setStyleSheet(stylesheet);
	//ui.pushButton_broadcast->setStyleSheet(stylesheet);
	//ui.pushButton_feedback->setStyleSheet(stylesheet);
	//ui.pushButton_aboutus->setStyleSheet(stylesheet);
	//ui.pushButton_shrink->setStyleSheet(stylesheet);

	ui.widgetLeft->setMaximumWidth(16777215);

	//ui.pushButton_shrink->setIcon(QIcon(':/RobotUI/Resources/left-left.svg'));

	_bLeftSideBarShrinked = false;
}

}

QSize RobotUI::sizeHint() const { return QSize(1000, 600); }

#include void RobotUI::mouseMoveEvent(QMouseEvent* event) { if (event->buttons() && Qt::LeftButton && _bPressed) { move(event->globalPos() - _pLast); event->accept(); }

if (isMaximized())
{
	return;
}

int iWidth = this->width();
int iHeight = this->height();

//if (event->pos().x() > iWidth - 10 && event->pos().y() > iHeight - 10)
//{
//	if (this->cursor() != Qt::SizeFDiagCursor)
//	{
//		this->setCursor(Qt::SizeFDiagCursor);
//	}

//	int width = this->width() - (this->width() - event->pos().x());
//	int height = this->height() - (this->height() - event->pos().y());

//	if (_bResize == true)
//	{
//		this->resize(width, height);
//		event->accept();
//	}
//}
//else
//{
//	this->setCursor(Qt::ArrowCursor);
//}

}

void RobotUI::mousePressEvent(QMouseEvent* event) { int width = this->width(); int height = this->height();

if (event->pos().x() > width - 10 && event->pos().y() > height - 10 && event->buttons() == Qt::LeftButton)
{
	_clickPos = event->pos();
	_bResize = true;
}
else if (event->button() == Qt::LeftButton && ui.widget->geometry().contains(event->pos()))
{
	_bPressed = true;
	_pLast = event->globalPos() - this->pos();

	event->accept();
}

}

void RobotUI::mouseReleaseEvent(QMouseEvent* event) { _bPressed = false; _bResize = false; }

#include #include

void RobotUI::paintEvent(QPaintEvent* event) { //QStyleOption opt; //opt.init(this); //QPainter p(this); //style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); //QWidget::paintEvent(event);

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);  // 反锯齿;
painter.setBrush(QBrush(Qt::red));
painter.setPen(Qt::transparent);
QRect rect = this->rect();
rect.setWidth(rect.width() - 1);
rect.setHeight(rect.height() - 1);
painter.drawRoundedRect(rect, 15, 15);
//也可用QPainterPath 绘制代替 painter.drawRoundedRect(rect, 15, 15);
{
	QPainterPath painterPath;
	painterPath.addRoundedRect(rect, 15, 15);
	painter.drawPath(painterPath);
}
QWidget::paintEvent(event);
C++ Qt 界面开发:RobotUI 类实现 - 控制台、玩家数据、程序设置等功能

原文地址: https://www.cveoy.top/t/topic/m2zj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录