#include "computermanager.h"
#include <QPushButton>
#include <QToolButton>
#include <QWidget>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QApplication>
#include <QWidgetAction>
#include <QLabel>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPainter>
#include "myswitchbutton.h"
ComputerManager::ComputerManager(QObject *parent) :
QSystemTrayIcon(parent)
{
this->initAction();
this->initTopAction();
this->initMidAction();
this->initBottomAction();
this->addActions();
this->initConnect();
this->translateActions();
}
void ComputerManager::translateActions()
{
m_tbnOpenSteward->setText(tr("Open"));
m_tbnHome->setText(tr("check"));
m_tbnAntiVirus->setText(tr("AntiVi"));
m_tbnCleanRubbish->setText(tr("Clean"));
m_tbnComputerSpeed->setText(tr("Comput"));
m_tbnComputerClinic->setText(tr("Clinic"));
}
bool ComputerManager::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_topWidget && event->type() == QEvent::Paint)
{
QPainter painter(m_topWidget);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(42,120,192));
painter.drawRect(m_topWidget->rect());
}
return QSystemTrayIcon::eventFilter(obj,event);
}
void ComputerManager::initTopAction()
{
//顶层菜单项初始化
m_topWidget = new QWidget();
m_topWidgetAction = new QWidgetAction(m_trayMenu);
m_topLabelIcon = new QLabel();
m_topLabelIcon->setPixmap(QPixmap(":/image/topicon.png"));
m_topLabelIcon->setFixedSize(30,30);
m_topLabel = new QLabel(tr("Comuter Manager now protected you!"));
m_topLabel->setObjectName(QString("WhiteLabel"));
m_topLabel->setFont(QFont("Times", 11));
QHBoxLayout* m_topLayout = new QHBoxLayout();
m_topLayout->addWidget(m_topLabelIcon);
m_topLayout->addWidget(m_topLabel,1,Qt::AlignHCenter | Qt::AlignVCenter);
m_topLayout->setContentsMargins(0,0,0,0);
m_topWidget->setLayout(m_topLayout);
m_topWidget->setMinimumHeight(70);
m_topWidget->installEventFilter(this);
m_topWidgetAction->setDefaultWidget(m_topWidget);
m_topQQWidget = new QWidget();
m_topQQWidgetAction = new QWidgetAction(m_trayMenu);
m_QQInfoBtn = new QLabel(tr("qq infor safety\n")+
tr("reinforce more secure"));
m_QQInfoBtn->setCursor(Qt::PointingHandCursor);
m_labelIcon = new QLabel();
m_labelIcon->setPixmap(QPixmap(":/image/icon.png"));
m_labelIcon->setFixedSize(50,50);
QHBoxLayout* m_topQQLayout = new QHBoxLayout();
m_topQQLayout->addWidget(m_labelIcon);
m_topQQLayout->addWidget(m_QQInfoBtn);
m_topQQLayout->setContentsMargins(0,0,0,0);
m_topQQWidget->setLayout(m_topQQLayout);
m_topQQWidget->setMinimumHeight(70);
m_topQQWidget->installEventFilter(this);
m_topQQWidgetAction->setDefaultWidget(m_topQQWidget);
m_topTbnWidget = new QWidget();
m_topTbnWidgetAction = new QWidgetAction(m_trayMenu);
m_tbnOpenSteward = new QToolButton();
m_tbnOpenSteward->setIcon(QIcon(":/image/1.png"));
m_tbnOpenSteward->setIconSize(QSize(50,50));
m_tbnOpenSteward->setAutoRaise(true);
m_tbnOpenSteward->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
m_tbnHome = new QToolButton();
m_tbnHome->setIcon(QIcon(":/image/2.png"));
m_tbnHome->setIconSize(QSize(50,50));
m_tbnHome->setAutoRaise(true);
m_tbnHome->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
m_tbnAntiVirus = new QToolButton();
m_tbnAntiVirus->setIcon(QIcon(":/image/3.png"));
m_tbnAntiVirus->setIconSize(QSize(50,50));
m_tbnAntiVirus->setAutoRaise(true);
m_tbnAntiVirus->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
m_tbnCleanRubbish = new QToolButton();
m_tbnCleanRubbish->setIcon(QIcon(":/image/4.png"));
m_tbnCleanRubbish->setIconSize(QSize(50,50));
m_tbnCleanRubbish->setAutoRaise(true);
m_tbnCleanRubbish->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
m_tbnComputerSpeed = new QToolButton();
m_tbnComputerSpeed->setIcon(QIcon(":/image/5.png"));
m_tbnComputerSpeed->setIconSize(QSize(50,50));
m_tbnComputerSpeed->setAutoRaise(true);
m_tbnComputerSpeed->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
m_tbnComputerClinic = new QToolButton();
m_tbnComputerClinic->setIcon(QIcon(":/image/6.png"));
m_tbnComputerClinic->setIconSize(QSize(50,50));
m_tbnComputerClinic->setAutoRaise(true);
m_tbnComputerClinic->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QHBoxLayout *layout1 = new QHBoxLayout();
layout1->addWidget(m_tbnOpenSteward);
layout1->addWidget(m_tbnHome);
layout1->setContentsMargins(0,0,0,0);
QHBoxLayout *layout2 = new QHBoxLayout();
layout2->addWidget(m_tbnAntiVirus);
layout2->addWidget(m_tbnCleanRubbish);
layout2->setContentsMargins(0,0,0,0);
QHBoxLayout *layout3 = new QHBoxLayout();
layout3->addWidget(m_tbnComputerSpeed);
layout3->addWidget(m_tbnComputerClinic);
layout3->setContentsMargins(0,0,0,0);
QVBoxLayout *mainLout = new QVBoxLayout();
mainLout->addLayout(layout1);
mainLout->addLayout(layout2);
mainLout->addLayout(layout3);
mainLout->setContentsMargins(0,0,0,0);
m_topTbnWidget->setLayout(mainLout);
m_topTbnWidgetAction->setDefaultWidget(m_topTbnWidget);
}
void ComputerManager::initMidAction()
{
m_midWidget = new QWidget();
m_midWidgetAction = new QWidgetAction(m_trayMenu);
m_speedLabel = new QLabel(tr("Auto backup"));
m_SpeedBtn = new mySwitchButton();
m_SpeedBtn->setFixedSize(60,25);
m_SpeedBtn->setObjectName(QString("TrayButtonAuto"));
m_SpeedBtn->SetCheck(true);
QHBoxLayout *m_midUpLayout = new QHBoxLayout();
m_midUpLayout->addWidget(m_speedLabel);
m_midUpLayout->addWidget(m_SpeedBtn);
m_troubleLabel = new QLabel(tr("Auto Start"));
m_troubleLabel->setToolTip(tr("computer now "));
m_TroubleBtn = new mySwitchButton();
m_TroubleBtn->setFixedSize(60,25);
m_TroubleBtn->setObjectName(QString("TrayButtonAuto"));
m_TroubleBtn->SetCheck(true);
QHBoxLayout *m_midBottomLayout = new QHBoxLayout();
m_midBottomLayout->addWidget(m_troubleLabel);
m_midBottomLayout->addWidget(m_TroubleBtn);
QVBoxLayout *m_midMainLayout = new QVBoxLayout();
m_midMainLayout->addLayout(m_midUpLayout);
m_midMainLayout->addLayout(m_midBottomLayout);
m_midWidget->setLayout(m_midMainLayout);
m_midWidgetAction->setDefaultWidget(m_midWidget);
}
void ComputerManager::initBottomAction()
{
m_bottomWidget = new QWidget();
m_bottomWidgetAction = new QWidgetAction(m_trayMenu);
m_ReportBtn = new QPushButton(QIcon(":/image/mainMenu/update.png"), tr("Update"));
m_ReportBtn->setObjectName(QString("TrayButton"));
m_ReportBtn->setFixedSize(60, 25);
m_InformBtn = new QPushButton(QIcon(":/image/mainMenu/about.png"), tr("About"));
m_InformBtn->setObjectName(QString("TrayButton"));
m_InformBtn->setFixedSize(60, 25);
m_exitBtn = new QPushButton(QIcon(":/image/mainMenu/quit.png"), tr("Exit"));
m_exitBtn->setObjectName(QString("TrayButton"));
m_exitBtn->setFixedSize(60, 25);
QHBoxLayout* m_bottomLayout = new QHBoxLayout();
m_bottomLayout->addWidget(m_ReportBtn, 0, Qt::AlignCenter);
m_bottomLayout->addWidget(m_InformBtn, 0, Qt::AlignCenter);
m_bottomLayout->addWidget(m_exitBtn, 0, Qt::AlignCenter);
m_bottomLayout->setSpacing(5);
m_bottomLayout->setContentsMargins(5,5,5,5);
m_bottomWidget->setLayout(m_bottomLayout);
m_bottomWidgetAction->setDefaultWidget(m_bottomWidget);
}
void ComputerManager::initAction()
{
this->setToolTip(tr("Computer Manager"));
this->setIcon(QIcon(":/image/system_tray.png"));
m_trayMenu = new QM
Qt个性化系统托盘的实现
5星 · 超过95%的资源 需积分: 50 152 浏览量
2015-10-31
14:06:00
上传
评论 8
收藏 95KB 7Z 举报
devstone
- 粉丝: 2204
- 资源: 27
最新资源
- database-project-massunaAi笔记
- 2%EF%BC%9A%E9%99%95%E8%A5%BF%E
- yyspdz62_944.apk
- SAP公司间采购EDI配置-如何触发自动MIRO.docx
- python197基于图像识别的仪表实时监控系统.rar
- python196基于循环神经网络的情感分类系统.rar
- I2C驱动SHT30温湿度传感器和LCD12864使用例程(RSCG12864B)
- python193中学地理-中国的江河湖泊教学网(django).rar
- python191基于时间序列分析的大气污染预测软件(django).rar
- python190基于人脸识别智能化小区门禁管理系统.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页