Add myhoverbutton, mytristatebutton and myunderlinebutton
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "diskitem.h"
|
||||
#include "../widgets/myimagebutton.h"
|
||||
#include "../widgets/mytristatebutton.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
|
@ -35,7 +35,7 @@ DiskItem::DiskItem(QWidget *parent)
|
|||
,m_availLabel(new QLabel)
|
||||
,m_usedLabel(new QLabel)
|
||||
,m_percentageLabel(new QLabel)
|
||||
,m_detailBtn(new MyImageButton)
|
||||
,m_detailBtn(new MyTristateButton)
|
||||
{
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
this->setFixedHeight(36);
|
||||
|
@ -58,7 +58,7 @@ DiskItem::DiskItem(QWidget *parent)
|
|||
setLayout(mainLayout);
|
||||
|
||||
m_detailBtn->setObjectName("DiskDetailButton");
|
||||
connect(m_detailBtn, &MyImageButton::clicked, this, [=] {
|
||||
connect(m_detailBtn, &MyTristateButton::clicked, this, [=] {
|
||||
//TODO: show detail dialog
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <QMapNode>
|
||||
#include <QLabel>
|
||||
|
||||
class MyImageButton;
|
||||
class MyTristateButton;
|
||||
|
||||
class DiskItem : public QFrame
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ private:
|
|||
QLabel *m_availLabel;
|
||||
QLabel *m_usedLabel;
|
||||
QLabel *m_percentageLabel;
|
||||
MyImageButton *m_detailBtn;
|
||||
MyTristateButton *m_detailBtn;
|
||||
bool m_isHead;
|
||||
bool m_isTail;
|
||||
};
|
||||
|
|
|
@ -18,23 +18,27 @@
|
|||
*/
|
||||
|
||||
#include "monitortitlewidget.h"
|
||||
#include "../widgets/myimagebutton.h"
|
||||
#include "../widgets/mytipimagebutton.h"
|
||||
#include "../widgets/mytristatebutton.h"
|
||||
#include "../widgets/myunderlinebutton.h"
|
||||
#include "../widgets/mysearchedit.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include <QStyleFactory>
|
||||
|
||||
MonitorTitleWidget::MonitorTitleWidget(QWidget *parent)
|
||||
MonitorTitleWidget::MonitorTitleWidget(QSettings *settings, QWidget *parent)
|
||||
:QFrame(parent)
|
||||
,proSettings(settings)
|
||||
{
|
||||
installEventFilter(this);
|
||||
setMouseTracking(true);
|
||||
setFixedHeight(TITLE_WIDGET_HEIGHT);
|
||||
setFixedHeight(MONITOR_TITLE_WIDGET_HEIGHT);
|
||||
|
||||
m_topBorderColor = QColor(255, 255, 255, 153);
|
||||
this->setAutoFillBackground(true);
|
||||
|
@ -42,20 +46,61 @@ MonitorTitleWidget::MonitorTitleWidget(QWidget *parent)
|
|||
palette.setColor(QPalette::Background, QColor("#0d87ca"));
|
||||
this->setPalette(palette);
|
||||
|
||||
m_searchTimer = new QTimer(this);
|
||||
m_searchTimer->setSingleShot(true);
|
||||
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(onRefreshSearchResult()));
|
||||
|
||||
initWidgets();
|
||||
}
|
||||
|
||||
MonitorTitleWidget::~MonitorTitleWidget()
|
||||
{
|
||||
delete emptyLabel;
|
||||
delete m_searchEdit;
|
||||
delete m_cancelSearchBtn;
|
||||
|
||||
if (m_searchTimer) {
|
||||
disconnect(m_searchTimer, SIGNAL(timeout()), this, SLOT(onRefreshSearchResult()));
|
||||
if(m_searchTimer->isActive()) {
|
||||
m_searchTimer->stop();
|
||||
}
|
||||
delete m_searchTimer;
|
||||
m_searchTimer = nullptr;
|
||||
}
|
||||
|
||||
//Segmentation fault
|
||||
QLayoutItem *child;
|
||||
while ((child = m_lLayout->takeAt(0)) != 0) {
|
||||
while ((child = m_titleLeftLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
|
||||
while ((child = m_rLayout->takeAt(0)) != 0) {
|
||||
while ((child = m_titleMiddleLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
while ((child = m_titleRightLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
while ((child = m_toolLeftLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
while ((child = m_toolRightLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
while ((child = m_topLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
while ((child = m_bottomLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
|
@ -63,6 +108,62 @@ MonitorTitleWidget::~MonitorTitleWidget()
|
|||
delete m_layout;
|
||||
}
|
||||
|
||||
bool MonitorTitleWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
if (obj == this) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Escape) {
|
||||
m_searchEdit->clearEdit();
|
||||
emit canelSearchEditFocus();
|
||||
}
|
||||
}
|
||||
else if (obj == m_searchEdit->getLineEdit()) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Tab) {
|
||||
emit canelSearchEditFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QFrame::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::setSearchEditFocus()
|
||||
{
|
||||
if (m_searchEdit->text() != "") {
|
||||
m_searchEdit->getLineEdit()->setFocus();
|
||||
} else {
|
||||
m_searchEdit->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::onRefreshSearchResult()
|
||||
{
|
||||
if (m_searchEdit->text() == searchTextCache) {
|
||||
emit this->searchSignal(searchTextCache);
|
||||
}
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::handleSearchTextChanged()
|
||||
{
|
||||
searchTextCache = m_searchEdit->text();
|
||||
|
||||
this->m_cancelSearchBtn->setVisible(!searchTextCache.isEmpty());
|
||||
|
||||
if (m_searchTimer->isActive()) {
|
||||
m_searchTimer->stop();
|
||||
}
|
||||
m_searchTimer->start(300);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::onCancelSearchBtnClicked(bool b)
|
||||
{
|
||||
this->m_cancelSearchBtn->setVisible(false);
|
||||
m_searchEdit->clearEdit();
|
||||
emit canelSearchEditFocus();
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::mouseDoubleClickEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
|
@ -77,7 +178,6 @@ void MonitorTitleWidget::mouseDoubleClickEvent(QMouseEvent *e)
|
|||
|
||||
void MonitorTitleWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
|
||||
QFrame::paintEvent(e);
|
||||
|
||||
QPainter p(this);
|
||||
|
@ -92,46 +192,52 @@ void MonitorTitleWidget::paintEvent(QPaintEvent *e)
|
|||
p.drawPath(tPath);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::initLeftContent()
|
||||
void MonitorTitleWidget::initTitlebarLeftContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
m_lLayout = new QHBoxLayout(w);
|
||||
m_lLayout->setContentsMargins(6, 0, 0, 0);
|
||||
m_lLayout->setSpacing(0);
|
||||
m_titleLeftLayout = new QHBoxLayout(w);
|
||||
m_titleLeftLayout->setContentsMargins(6, 0, 0, 0);
|
||||
m_titleLeftLayout->setSpacing(0);
|
||||
|
||||
QLabel *label = new QLabel;
|
||||
label->setStyleSheet("QLabel{border-image: url(://res/kylin-assistant.png);}");
|
||||
label->setFixedSize(24, 24);
|
||||
m_lLayout->addWidget(label);
|
||||
emptyLabel = new QLabel;
|
||||
emptyLabel->setStyleSheet("QLabel{background-color:transparent;}");
|
||||
m_titleLeftLayout->addWidget(emptyLabel);
|
||||
|
||||
m_topLayout->addWidget(w, 1, Qt::AlignLeft);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::initTitlebarMiddleContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
m_titleMiddleLayout = new QHBoxLayout(w);
|
||||
m_titleMiddleLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
QLabel *titleLabel = new QLabel;
|
||||
titleLabel->setStyleSheet("QLabel{background-color:transparent;color:#ffffff; font-size:12px;}");
|
||||
titleLabel->setText(tr("Kylin System Monitor"));
|
||||
m_lLayout->addSpacing(5);
|
||||
m_lLayout->addWidget(titleLabel);
|
||||
|
||||
m_layout->addWidget(w, 1, Qt::AlignLeft);
|
||||
m_titleMiddleLayout->addWidget(titleLabel);
|
||||
m_topLayout->addWidget(w);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::initRightContent()
|
||||
void MonitorTitleWidget::initTitlebarRightContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
m_rLayout = new QHBoxLayout(w);
|
||||
m_rLayout->setContentsMargins(0, 0, 6, 0);
|
||||
m_rLayout->setSpacing(0);
|
||||
m_titleRightLayout = new QHBoxLayout(w);
|
||||
m_titleRightLayout->setContentsMargins(0, 0, 1, 0);
|
||||
m_titleRightLayout->setSpacing(0);
|
||||
|
||||
m_layout->addWidget(w, 1, Qt::AlignRight);
|
||||
m_topLayout->addWidget(w, 1, Qt::AlignRight);
|
||||
|
||||
MyImageButton *minBtn = new MyImageButton;
|
||||
MyTristateButton *minBtn = new MyTristateButton;
|
||||
minBtn->setObjectName("MinButton");
|
||||
connect(minBtn, &MyImageButton::clicked, this, [=] {
|
||||
connect(minBtn, &MyTristateButton::clicked, this, [=] {
|
||||
if (parentWidget() && parentWidget()->parentWidget()) {
|
||||
parentWidget()->parentWidget()->showMinimized();
|
||||
}
|
||||
});
|
||||
MyImageButton *maxBtn = new MyImageButton;
|
||||
MyTristateButton *maxBtn = new MyTristateButton;
|
||||
maxBtn->setObjectName("MaxButton");
|
||||
connect(maxBtn, &MyImageButton::clicked, this, [=] {
|
||||
connect(maxBtn, &MyTristateButton::clicked, this, [=] {
|
||||
if (window()->isMaximized()) {
|
||||
window()->showNormal();
|
||||
maxBtn->setObjectName("MaxButton");
|
||||
|
@ -148,24 +254,126 @@ void MonitorTitleWidget::initRightContent()
|
|||
maxBtn->setObjectName("MaxButton");
|
||||
}
|
||||
});
|
||||
MyImageButton *closeBtn = new MyImageButton;
|
||||
MyTristateButton *closeBtn = new MyTristateButton;
|
||||
closeBtn->setObjectName("CloseButton");
|
||||
connect(closeBtn, &MyImageButton::clicked, this, [=] {
|
||||
connect(closeBtn, &MyTristateButton::clicked, this, [=] {
|
||||
window()->close();
|
||||
});
|
||||
|
||||
m_rLayout->addWidget(minBtn);
|
||||
m_rLayout->addWidget(maxBtn);
|
||||
m_rLayout->addWidget(closeBtn);
|
||||
m_titleRightLayout->addWidget(minBtn);
|
||||
m_titleRightLayout->addWidget(maxBtn);
|
||||
m_titleRightLayout->addWidget(closeBtn);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::initToolbarLeftContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
m_toolLeftLayout = new QHBoxLayout(w);
|
||||
m_toolLeftLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_toolLeftLayout->setSpacing(0);
|
||||
|
||||
MyUnderLineButton *processButton = new MyUnderLineButton();
|
||||
processButton->setName(tr("Processes"));
|
||||
processButton->setChecked(true);
|
||||
|
||||
MyUnderLineButton *resourcesButton = new MyUnderLineButton();
|
||||
resourcesButton->setName(tr("Resources"));
|
||||
resourcesButton->setChecked(false);
|
||||
|
||||
MyUnderLineButton *disksButton = new MyUnderLineButton();
|
||||
disksButton->setName(tr("File Systems"));
|
||||
disksButton->setChecked(false);
|
||||
|
||||
connect(processButton, &MyUnderLineButton::clicked, this, [=] {
|
||||
emit this->changePage(0);
|
||||
processButton->setChecked(true);
|
||||
resourcesButton->setChecked(false);
|
||||
disksButton->setChecked(false);
|
||||
if (!m_searchEdit->isVisible())
|
||||
m_searchEdit->setVisible(true);
|
||||
});
|
||||
connect(resourcesButton, &MyUnderLineButton::clicked, this, [=] {
|
||||
emit this->changePage(1);
|
||||
processButton->setChecked(false);
|
||||
resourcesButton->setChecked(true);
|
||||
disksButton->setChecked(false);
|
||||
if (m_searchEdit->isVisible())
|
||||
m_searchEdit->setVisible(false);
|
||||
m_searchEdit->clearEdit();
|
||||
emit canelSearchEditFocus();
|
||||
});
|
||||
connect(disksButton, &MyUnderLineButton::clicked, this, [=] {
|
||||
emit this->changePage(2);
|
||||
processButton->setChecked(false);
|
||||
resourcesButton->setChecked(false);
|
||||
disksButton->setChecked(true);
|
||||
if (m_searchEdit->isVisible())
|
||||
m_searchEdit->setVisible(false);
|
||||
m_searchEdit->clearEdit();
|
||||
emit canelSearchEditFocus();
|
||||
});
|
||||
|
||||
m_toolLeftLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_toolLeftLayout->setSpacing(10);
|
||||
m_toolLeftLayout->addStretch();
|
||||
m_toolLeftLayout->addWidget(processButton);
|
||||
m_toolLeftLayout->addWidget(resourcesButton);
|
||||
m_toolLeftLayout->addWidget(disksButton);
|
||||
m_toolLeftLayout->addStretch();
|
||||
|
||||
// m_bottomLayout->addWidget(w);
|
||||
m_bottomLayout->addWidget(w, 1, Qt::AlignLeft);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::initToolbarRightContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
m_toolRightLayout = new QHBoxLayout(w);
|
||||
m_toolRightLayout->setContentsMargins(0, 3, 6, 10);
|
||||
m_toolRightLayout->setSpacing(5);
|
||||
|
||||
m_cancelSearchBtn = new QPushButton;
|
||||
m_cancelSearchBtn->setStyleSheet("QPushButton{background-color:transparent;text-align:center;font-family: 方正黑体_GBK;font-size:11px;color:#ffffff;}QPushButton:hover{color:#000000;}");
|
||||
m_cancelSearchBtn->setText(tr("Cancel"));
|
||||
m_cancelSearchBtn->setFocusPolicy(Qt::NoFocus);
|
||||
m_cancelSearchBtn->setFixedSize(46, 25);
|
||||
m_cancelSearchBtn->setVisible(false);
|
||||
connect(m_cancelSearchBtn, SIGNAL(clicked(bool)), SLOT(onCancelSearchBtnClicked(bool)));
|
||||
connect(m_searchEdit, &MySearchEdit::textChanged, this, &MonitorTitleWidget::handleSearchTextChanged, Qt::QueuedConnection);
|
||||
m_toolRightLayout->addWidget(m_searchEdit);
|
||||
m_toolRightLayout->addWidget(m_cancelSearchBtn);
|
||||
m_bottomLayout->addWidget(w, 1, Qt::AlignRight);
|
||||
}
|
||||
|
||||
void MonitorTitleWidget::initWidgets()
|
||||
{
|
||||
m_layout = new QHBoxLayout(this);
|
||||
m_searchEdit = new MySearchEdit();
|
||||
m_searchEdit->setPlaceHolder(tr("Enter the relevant info of process"));
|
||||
m_searchEdit->setFixedSize(222, 30);
|
||||
m_searchEdit->getLineEdit()->installEventFilter(this);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setSpacing(0);
|
||||
|
||||
QWidget *topWidget = new QWidget;
|
||||
m_topLayout = new QHBoxLayout(topWidget);
|
||||
m_topLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_topLayout->setSpacing(0);
|
||||
m_layout->addWidget(topWidget, 0, Qt::AlignTop);
|
||||
|
||||
QWidget *bottomWidget = new QWidget;
|
||||
m_bottomLayout = new QHBoxLayout(bottomWidget);
|
||||
m_bottomLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_bottomLayout->setSpacing(0);
|
||||
m_layout->addWidget(bottomWidget, 0, Qt::AlignBottom);
|
||||
|
||||
this->setLayout(m_layout);
|
||||
|
||||
initLeftContent();
|
||||
initRightContent();
|
||||
initTitlebarLeftContent();
|
||||
initTitlebarMiddleContent();
|
||||
initTitlebarRightContent();
|
||||
initToolbarLeftContent();
|
||||
initToolbarRightContent();
|
||||
}
|
||||
|
|
|
@ -22,31 +22,60 @@
|
|||
|
||||
#include <QFrame>
|
||||
#include <QTimer>
|
||||
#include <QSettings>
|
||||
|
||||
class QVBoxLayout;
|
||||
class QHBoxLayout;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class MySearchEdit;
|
||||
|
||||
class MonitorTitleWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MonitorTitleWidget(QWidget *parent);
|
||||
MonitorTitleWidget(QSettings *settings, QWidget *parent);
|
||||
~MonitorTitleWidget();
|
||||
void initLeftContent();
|
||||
void initRightContent();
|
||||
void initTitlebarLeftContent();
|
||||
void initTitlebarMiddleContent();
|
||||
void initTitlebarRightContent();
|
||||
void initToolbarLeftContent();
|
||||
void initToolbarRightContent();
|
||||
void initWidgets();
|
||||
void setSearchEditFocus();
|
||||
|
||||
public slots:
|
||||
void onRefreshSearchResult();
|
||||
void handleSearchTextChanged();
|
||||
void onCancelSearchBtnClicked(bool b);
|
||||
|
||||
signals:
|
||||
void updateMaxBtn();
|
||||
void changePage(int index);
|
||||
void searchSignal(QString searchContent);
|
||||
void canelSearchEditFocus();
|
||||
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
signals:
|
||||
void updateMaxBtn();
|
||||
bool eventFilter(QObject *, QEvent *event) override;
|
||||
|
||||
private:
|
||||
QSettings *proSettings;
|
||||
QColor m_topBorderColor;
|
||||
QHBoxLayout *m_layout;
|
||||
QHBoxLayout *m_lLayout;
|
||||
QHBoxLayout *m_rLayout;
|
||||
MySearchEdit *m_searchEdit = nullptr;
|
||||
QPushButton *m_cancelSearchBtn = nullptr;
|
||||
QString searchTextCache;
|
||||
QTimer *m_searchTimer = nullptr;
|
||||
QLabel *emptyLabel = nullptr;
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
QHBoxLayout *m_topLayout = nullptr;
|
||||
QHBoxLayout *m_titleMiddleLayout = nullptr;
|
||||
QHBoxLayout *m_titleRightLayout = nullptr;
|
||||
QHBoxLayout *m_bottomLayout = nullptr;
|
||||
QHBoxLayout *m_titleLeftLayout = nullptr;
|
||||
QHBoxLayout *m_toolLeftLayout = nullptr;
|
||||
QHBoxLayout *m_toolRightLayout = nullptr;
|
||||
};
|
||||
|
||||
#endif // MONITORTITLEWIDGET_H
|
||||
|
|
|
@ -245,7 +245,7 @@ void NetworkFlow::paintEvent(QPaintEvent *)
|
|||
painter.setPen(QPen(QColor("#303030")));
|
||||
painter.drawText(QRect(rect().x() + 2, rect().y(), rect().width() - 4, rect().height()), Qt::AlignLeft | Qt::AlignTop, tr("Network"));//绘制文本
|
||||
|
||||
setFontSize(painter, 9);
|
||||
setFontSize(painter, 12);
|
||||
QFontMetrics fm = painter.fontMetrics();
|
||||
QString downloadTitle = QString("%1 %2").arg(tr("Receiving")).arg(formatNetworkRate(m_recvRateBytes));
|
||||
QString downloadContent = QString("%1 %2").arg(tr("Total Received")).arg(formatNetwork(m_recvTotalBytes));//接收
|
||||
|
@ -267,7 +267,7 @@ void NetworkFlow::paintEvent(QPaintEvent *)
|
|||
// uploadPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);//输出是源,其中alpha被目标的值减少 设置画刷的组合模式CompositionMode_SourceIn这个模式为目标图像在下
|
||||
// uploadPainter.end();
|
||||
|
||||
setFontSize(painter, 9);
|
||||
setFontSize(painter, 12);
|
||||
painter.setPen(QPen(QColor("#1E90FF")));
|
||||
painter.drawText(QRect(rect().x() + 20 + 5, rect().y() + 40, fm.width(downloadTitle), rect().height()), Qt::AlignLeft | Qt::AlignTop, downloadTitle);
|
||||
painter.drawText(QRect(rect().x() + 20 + rateW + 14, rect().y() + 40, fm.width(downloadContent), rect().height()), Qt::AlignLeft | Qt::AlignTop, downloadContent);
|
||||
|
@ -284,7 +284,7 @@ void NetworkFlow::paintEvent(QPaintEvent *)
|
|||
// downloadPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);//输出是源,其中alpha被目标的值减少 设置画刷的组合模式CompositionMode_SourceIn这个模式为目标图像在下
|
||||
// downloadPainter.end();
|
||||
|
||||
setFontSize(painter, 9);
|
||||
setFontSize(painter, 12);
|
||||
painter.setPen(QPen(QColor("#FF0000")));
|
||||
painter.drawText(QRect(rect().x() + 20 + 5, rect().y() + 70, fm.width(uploadTitle), rect().height()), Qt::AlignLeft | Qt::AlignTop, uploadTitle);
|
||||
painter.drawText(QRect(rect().x() + 20 + rateW + 14, rect().y() + 70, fm.width(uploadContent), rect().height()), Qt::AlignLeft | Qt::AlignTop, uploadContent);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "processcategory.h"
|
||||
#include "../widgets/myimagebutton.h"
|
||||
#include "../widgets/myhoverbutton.h"
|
||||
|
||||
ProcessCategory::ProcessCategory(int tabIndex, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
|
@ -32,17 +32,12 @@ ProcessCategory::ProcessCategory(int tabIndex, QWidget *parent)
|
|||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
activeProcessButton = new MyImageButton(this);
|
||||
activeProcessButton->setCheckable(true);
|
||||
activeProcessButton->setObjectName("ActiveProcessBtn");
|
||||
|
||||
userProcessButton = new MyImageButton(this);
|
||||
userProcessButton->setCheckable(true);
|
||||
userProcessButton->setObjectName("UserProcessBtn");
|
||||
|
||||
allProcessButton = new MyImageButton(this);
|
||||
allProcessButton->setCheckable(true);
|
||||
allProcessButton->setObjectName("AllProcessBtn");
|
||||
activeProcessButton = new MyHoverButton(this);
|
||||
activeProcessButton->setPicture(":/res/active_proc.png");
|
||||
userProcessButton = new MyHoverButton(this);
|
||||
userProcessButton->setPicture(":/res/user_proc.png");
|
||||
allProcessButton = new MyHoverButton(this);
|
||||
allProcessButton->setPicture(":/res/all_proc.png");
|
||||
|
||||
if (activeIndex == 0) {
|
||||
activeProcessButton->setChecked(true);
|
||||
|
@ -60,21 +55,21 @@ ProcessCategory::ProcessCategory(int tabIndex, QWidget *parent)
|
|||
allProcessButton->setChecked(false);
|
||||
}
|
||||
|
||||
connect(activeProcessButton, &MyImageButton::clicked, this, [=] {
|
||||
connect(activeProcessButton, &MyHoverButton::clicked, this, [=] {
|
||||
activeIndex = 0;
|
||||
emit this->activeWhoseProcessList(activeIndex);
|
||||
activeProcessButton->setChecked(true);
|
||||
userProcessButton->setChecked(false);
|
||||
allProcessButton->setChecked(false);
|
||||
});
|
||||
connect(userProcessButton, &MyImageButton::clicked, this, [=] {
|
||||
connect(userProcessButton, &MyHoverButton::clicked, this, [=] {
|
||||
activeIndex = 1;
|
||||
emit this->activeWhoseProcessList(activeIndex);
|
||||
activeProcessButton->setChecked(false);
|
||||
userProcessButton->setChecked(true);
|
||||
allProcessButton->setChecked(false);
|
||||
});
|
||||
connect(allProcessButton, &MyImageButton::clicked, this, [=] {
|
||||
connect(allProcessButton, &MyHoverButton::clicked, this, [=] {
|
||||
activeIndex = 2;
|
||||
emit this->activeWhoseProcessList(activeIndex);
|
||||
activeProcessButton->setChecked(false);
|
||||
|
|
|
@ -17,14 +17,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PROCESSCATEGORY_H
|
||||
#define PROCESSCATEGORY_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
class MyImageButton;
|
||||
class MyHoverButton;
|
||||
|
||||
class ProcessCategory : public QWidget
|
||||
{
|
||||
|
@ -42,9 +41,9 @@ private:
|
|||
int height;
|
||||
int activeIndex;
|
||||
QHBoxLayout *layout = nullptr;
|
||||
MyImageButton *activeProcessButton = nullptr;
|
||||
MyImageButton *userProcessButton = nullptr;
|
||||
MyImageButton *allProcessButton = nullptr;
|
||||
MyHoverButton *activeProcessButton = nullptr;
|
||||
MyHoverButton *userProcessButton = nullptr;
|
||||
MyHoverButton *allProcessButton = nullptr;
|
||||
};
|
||||
|
||||
#endif // PROCESSCATEGORY_H
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "processdialog.h"
|
||||
#include "propertiesdialog.h"
|
||||
#include "processdata.h"
|
||||
#include "processcategory.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
@ -32,6 +33,7 @@
|
|||
#include <QHeaderView>
|
||||
#include <QDesktopServices>
|
||||
#include <QApplication>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
|
@ -103,14 +105,15 @@ ProcessDialog::ProcessDialog(QList<bool> toBeDisplayedColumns, int currentSortIn
|
|||
|
||||
actionPids = new QList<pid_t>();
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setSpacing(0);
|
||||
|
||||
m_processListWidget = new ProcessListWidget(toBeDisplayedColumns);
|
||||
connect(m_processListWidget, SIGNAL(changeColumnVisible(int,bool,QList<bool>)), this, SIGNAL(changeColumnVisible(int,bool,QList<bool>)));
|
||||
connect(m_processListWidget, SIGNAL(changeSortStatus(int,bool)), this, SIGNAL(changeSortStatus(int,bool)));
|
||||
connect(m_processListWidget, &ProcessListWidget::rightMouseClickedItems, this, &ProcessDialog::popupMenu, Qt::QueuedConnection);
|
||||
layout->addWidget(m_processListWidget);
|
||||
m_layout->addWidget(m_processListWidget);
|
||||
|
||||
whose_processes = "user";
|
||||
proSettings->beginGroup("PROCESS");
|
||||
|
@ -128,6 +131,24 @@ ProcessDialog::ProcessDialog(QList<bool> toBeDisplayedColumns, int currentSortIn
|
|||
tabIndex = 1;
|
||||
}
|
||||
|
||||
|
||||
QWidget *w = new QWidget;
|
||||
w->setFixedHeight(50);
|
||||
m_categoryLayout = new QHBoxLayout(w);
|
||||
m_categoryLayout->setContentsMargins(0, 0, 6, 3);
|
||||
m_categoryLayout->setSpacing(10);
|
||||
processCategory = new ProcessCategory(tabIndex);
|
||||
connect(processCategory, SIGNAL(activeWhoseProcessList(int)), this, SLOT(onActiveWhoseProcess(int)));
|
||||
m_categoryLayout->addWidget(processCategory, 0, Qt::AlignRight);
|
||||
m_layout->addWidget(w);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QList<SortFunction> *sortFuncList = new QList<SortFunction>();
|
||||
sortFuncList->append(&ProcessListItem::sortByName);
|
||||
sortFuncList->append(&ProcessListItem::sortByUser);
|
||||
|
@ -218,7 +239,7 @@ ProcessDialog::~ProcessDialog()
|
|||
delete timer;
|
||||
timer = NULL;
|
||||
}
|
||||
|
||||
delete processCategory;
|
||||
delete endProcessDialog;
|
||||
delete killProcessDialog;
|
||||
delete m_processListWidget;
|
||||
|
@ -236,6 +257,14 @@ ProcessDialog::~ProcessDialog()
|
|||
delete m_propertiyAction;
|
||||
delete m_menu;
|
||||
delete actionPids;
|
||||
|
||||
QLayoutItem *child;
|
||||
while ((child = m_categoryLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
delete m_layout;
|
||||
}
|
||||
|
||||
void ProcessDialog::displayAllProcess()
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <QSettings>
|
||||
|
||||
class ProcessManager;
|
||||
class ProcessCategory;
|
||||
|
||||
class ProcessDialog : public QWidget
|
||||
{
|
||||
|
@ -62,6 +63,7 @@ public:
|
|||
signals:
|
||||
void changeColumnVisible(int index, bool visible, QList<bool> columnVisible);
|
||||
void changeSortStatus(int index, bool isSort);
|
||||
void activeWhoseProcessList(int index);
|
||||
|
||||
public slots:
|
||||
void focusProcessView();
|
||||
|
@ -82,29 +84,33 @@ public slots:
|
|||
void refreshProcessList();
|
||||
|
||||
private:
|
||||
QTimer *timer = nullptr;
|
||||
QSettings *proSettings = nullptr;
|
||||
guint64 cpu_total_time;
|
||||
guint64 cpu_total_time_last;
|
||||
MyDialog *killProcessDialog = nullptr;
|
||||
MyDialog *endProcessDialog = nullptr;
|
||||
ProcessListWidget *m_processListWidget = nullptr;
|
||||
QAction *m_propertiyAction = nullptr;
|
||||
QAction *m_stopAction = nullptr;//停止
|
||||
QAction *m_continueAction = nullptr;//继续进程
|
||||
QAction *m_endAction = nullptr;//结束
|
||||
QAction *m_killAction = nullptr;//杀死
|
||||
// QMenu *m_priorityMenu;
|
||||
// MyActionGroup * priorityGroup;
|
||||
// MyAction *veryHighAction;
|
||||
// MyAction *highAction;
|
||||
// MyAction *normalAction;
|
||||
// MyAction *lowAction;
|
||||
// MyAction *veryLowAction;
|
||||
// MyAction *customAction;
|
||||
QList<pid_t> *actionPids;
|
||||
QMenu *m_menu = nullptr;
|
||||
QString whose_processes;
|
||||
gint num_cpus;
|
||||
unsigned frequency;
|
||||
QTimer *timer = nullptr;
|
||||
QSettings *proSettings = nullptr;
|
||||
guint64 cpu_total_time;
|
||||
guint64 cpu_total_time_last;
|
||||
MyDialog *killProcessDialog = nullptr;
|
||||
MyDialog *endProcessDialog = nullptr;
|
||||
ProcessListWidget *m_processListWidget = nullptr;
|
||||
QAction *m_propertiyAction = nullptr;
|
||||
QAction *m_stopAction = nullptr;//停止
|
||||
QAction *m_continueAction = nullptr;//继续进程
|
||||
QAction *m_endAction = nullptr;//结束
|
||||
QAction *m_killAction = nullptr;//杀死
|
||||
ProcessCategory *processCategory = nullptr;
|
||||
// QMenu *m_priorityMenu;
|
||||
// MyActionGroup * priorityGroup;
|
||||
// MyAction *veryHighAction;
|
||||
// MyAction *highAction;
|
||||
// MyAction *normalAction;
|
||||
// MyAction *lowAction;
|
||||
// MyAction *veryLowAction;
|
||||
// MyAction *customAction;
|
||||
QList<pid_t> *actionPids;
|
||||
QMenu *m_menu = nullptr;
|
||||
QString whose_processes;
|
||||
gint num_cpus;
|
||||
unsigned frequency;
|
||||
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
QHBoxLayout *m_categoryLayout = nullptr;
|
||||
};
|
||||
|
|
|
@ -42,42 +42,37 @@ void ProcessListItem::drawBackground(QRect rect, QPainter *painter, int index, b
|
|||
path.addRect(QRectF(rect));
|
||||
|
||||
if (isSelect) {
|
||||
painter->setOpacity(1.0);
|
||||
painter->fillPath(path, QColor("#3f96e4"));
|
||||
painter->setOpacity(0.5);//0.1
|
||||
painter->fillPath(path, QColor("#2bb6ea"));
|
||||
}
|
||||
else {
|
||||
painter->setOpacity(0.02);
|
||||
painter->setOpacity(1);
|
||||
if (index % 2 == 0) {
|
||||
painter->fillPath(path, QColor("#000000"));
|
||||
painter->fillPath(path, QColor("#ffffff"));
|
||||
} else {
|
||||
painter->fillPath(path, QColor("#e9eef0"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessListItem::drawForeground(QRect rect, QPainter *painter, int column, int, bool isSelect)
|
||||
void ProcessListItem::drawForeground(QRect rect, QPainter *painter, int column, int, bool isSelect, bool isSeparator)
|
||||
{
|
||||
setFontSize(*painter, 9);
|
||||
setFontSize(*painter, 12);
|
||||
painter->setOpacity(1);
|
||||
if (isSelect) {
|
||||
painter->setPen(QPen(QColor("#ffffff")));
|
||||
} else {
|
||||
painter->setPen(QPen(QColor("#000000")));
|
||||
}
|
||||
painter->setPen(QPen(QColor("#000000")));
|
||||
if (column == 0) {
|
||||
painter->drawPixmap(QRect(rect.x() + padding, rect.y() + (rect.height() - iconSize) / 2, iconSize, iconSize), m_data.iconPixmap);
|
||||
QString name = m_data.processName;
|
||||
if (m_data.m_status == tr("Stopped")) {//已停止
|
||||
painter->setPen(QPen(QColor("#FA7053")));
|
||||
painter->setPen(QPen(QColor("#fff4c4")));
|
||||
name = QString("(%1) %2").arg(tr("Suspend")).arg(m_data.processName);
|
||||
}
|
||||
else if (m_data.m_status == tr("Zombie")) {//僵死
|
||||
painter->setPen(QPen(QColor("#808080")));
|
||||
painter->setPen(QPen(QColor("#fca71d")));
|
||||
name = QString("(%1) %2").arg(tr("No response")).arg(m_data.processName);
|
||||
|
||||
}
|
||||
else if (m_data.m_status == tr("Uninterruptible")) {//不可中断
|
||||
painter->setPen(QPen(QColor("#A52A2A")));
|
||||
painter->setPen(QPen(QColor("#f9eca8")));
|
||||
name = QString("(%1) %2").arg(tr("Uninterruptible")).arg(m_data.processName);
|
||||
}
|
||||
else {//Sleeping 睡眠中 Running 运行中
|
||||
|
@ -87,22 +82,61 @@ void ProcessListItem::drawForeground(QRect rect, QPainter *painter, int column,
|
|||
QFontMetrics fm(font);
|
||||
QString procName = fm.elidedText(name, Qt::ElideRight, nameMaxWidth);
|
||||
painter->drawText(QRect(rect.x() + iconSize + padding * 2, rect.y(), nameMaxWidth, rect.height()), Qt::AlignLeft | Qt::AlignVCenter, procName);
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
else if (column == 1) {
|
||||
if (!m_data.user.isEmpty()) {
|
||||
painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignCenter, m_data.user);
|
||||
}
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
else if (column == 2) {
|
||||
if (!m_data.m_status.isEmpty()) {
|
||||
painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignCenter, m_data.m_status);
|
||||
}
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
else if (column == 3) {
|
||||
if (m_data.cpu < 10) {
|
||||
painter->setPen(QPen(QColor("#fff4c4")));
|
||||
}
|
||||
else if (m_data.cpu < 33) {
|
||||
painter->setPen(QPen(QColor("#f9eca8")));
|
||||
}
|
||||
else {
|
||||
painter->setPen(QPen(QColor("#fca71d")));
|
||||
}
|
||||
painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignCenter, QString("%1%").arg(m_data.cpu));
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
else if (column == 4) {
|
||||
painter->drawText(QRect(rect.x(), rect.y(), rect.width() - padding, rect.height()), Qt::AlignCenter, QString("%1").arg(m_data.pid));
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
else if (column == 5) {
|
||||
int commandMaxWidth = rect.width();
|
||||
|
@ -110,15 +144,43 @@ void ProcessListItem::drawForeground(QRect rect, QPainter *painter, int column,
|
|||
QFontMetrics fm(font);
|
||||
QString command = fm.elidedText(m_data.commandLine, Qt::ElideRight, commandMaxWidth);
|
||||
painter->drawText(QRect(rect.x(), rect.y(), commandMaxWidth, rect.height()), Qt::AlignLeft | Qt::AlignVCenter, command);
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
else if (column == 6) {
|
||||
if (m_data.m_memory > 0) {
|
||||
painter->setOpacity(1);
|
||||
QString memory = QString(g_format_size_full(m_data.m_memory, G_FORMAT_SIZE_IEC_UNITS));
|
||||
if (m_data.m_memory < 102400000) {//<100M
|
||||
painter->setPen(QPen(QColor("#fff4c4")));
|
||||
}
|
||||
else if (m_data.m_memory < 1024000000) {//1G
|
||||
painter->setPen(QPen(QColor("#f9eca8")));
|
||||
}
|
||||
else {
|
||||
painter->setPen(QPen(QColor("#fca71d")));
|
||||
}
|
||||
painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignCenter, memory);
|
||||
}
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
else if (column == 7) {
|
||||
painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignLeft | Qt::AlignVCenter, getNiceLevel(m_data.m_nice));
|
||||
if (isSeparator) {
|
||||
painter->setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()));
|
||||
painter->fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
bool isSameItem(ProcessListItem *item);
|
||||
void drawBackground(QRect rect, QPainter *painter, int index, bool isSelect);
|
||||
void drawForeground(QRect rect, QPainter *painter, int column, int index, bool isSelect);
|
||||
void drawForeground(QRect rect, QPainter *painter, int column, int index, bool isSelect, bool isSeparator);
|
||||
static bool doSearch(const ProcessListItem *item, QString text);
|
||||
static bool sortByName(const ProcessListItem *item1, const ProcessListItem *item2, bool descendingSort);
|
||||
static bool sortByUser(const ProcessListItem *item1, const ProcessListItem *item2, bool descendingSort);
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
|
||||
ProcessListWidget::ProcessListWidget(QList<bool> toBeDisplayedColumns, QWidget *parent) : QWidget(parent)
|
||||
,m_titlePadding(10)
|
||||
,m_titleHeight(36)
|
||||
,m_rowHeight(36)
|
||||
,m_titleHeight(40)
|
||||
,m_rowHeight(29)
|
||||
,m_offSet(0)
|
||||
,m_origOffset(0)
|
||||
,m_scrollbarWidth(10)
|
||||
|
@ -51,19 +51,15 @@ ProcessListWidget::ProcessListWidget(QList<bool> toBeDisplayedColumns, QWidget *
|
|||
this->m_sortFuncList = new QList<SortFunction>();
|
||||
this->m_isSortList = new QList<bool>();
|
||||
|
||||
this->m_upArrowNormalPixmap = QPixmap(":/res/arrow_up_normal.png");
|
||||
this->m_upArrowHoverPixmap = QPixmap(":/res/arrow_up_hover.png");
|
||||
this->m_upArrowPressPixmap = QPixmap(":/res/arrow_up_press.png");
|
||||
this->m_downArrowNormalPixmap = QPixmap(":/res/arrow_down_normal.png");
|
||||
this->m_downArrowHoverPixmap = QPixmap(":/res/arrow_down_hover.png");
|
||||
this->m_downArrowPressPixmap = QPixmap(":/res/arrow_down_press.png");
|
||||
this->m_downArrowPixmap = QPixmap(":/res/arrow_down.png");
|
||||
this->m_upArrowPixmap = QPixmap(":/res/arrow_up.png");
|
||||
|
||||
this->columnTitles << tr("Process Name") << tr("User") << tr("Status") << tr("CPU") << tr("ID") << tr("Command Line") << tr("Memory") << tr("Priority");
|
||||
QList<int> widths;
|
||||
widths << 180 << 80 << 80 << 50 << 50 << -1 << 80 << 80;//-1时让改行填充所有剩余空间
|
||||
widths << 180 << 80 << 80 << 60 << 50 << -1 << 80 << 80;//-1时让改行填充所有剩余空间
|
||||
|
||||
QFont font;
|
||||
font.setPointSize(9);//需要和填充所有剩余空间的那个的文字字体大小一致
|
||||
font.setPixelSize(12);//需要和填充所有剩余空间的那个的文字字体大小一致 font.setPointSize(9)
|
||||
QFontMetrics fm(font);
|
||||
|
||||
this->m_columnWidths.clear();
|
||||
|
@ -71,7 +67,7 @@ ProcessListWidget::ProcessListWidget(QList<bool> toBeDisplayedColumns, QWidget *
|
|||
if (widths[i] == -1) {
|
||||
this->m_columnWidths << widths[i];
|
||||
} else {//-1时让改行填充所有剩余空间
|
||||
int maxWidth = fm.width(this->columnTitles[i]) + this->m_titlePadding + m_upArrowNormalPixmap.width() / m_upArrowNormalPixmap.devicePixelRatio() + 2 * 2;
|
||||
int maxWidth = fm.width(this->columnTitles[i]) + this->m_titlePadding + m_upArrowPixmap.width() / m_upArrowPixmap.devicePixelRatio() + 2 * 2;
|
||||
this->m_columnWidths << std::max(widths[i], maxWidth);
|
||||
}
|
||||
}
|
||||
|
@ -86,13 +82,20 @@ ProcessListWidget::ProcessListWidget(QList<bool> toBeDisplayedColumns, QWidget *
|
|||
|
||||
ProcessListWidget::~ProcessListWidget()
|
||||
{
|
||||
if (this->m_hideScrollbarTimer != NULL) {
|
||||
disconnect(this->m_hideScrollbarTimer,SIGNAL(timeout()),this,SLOT(hideScrollbar()));
|
||||
if(this->m_hideScrollbarTimer->isActive()) {
|
||||
this->m_hideScrollbarTimer->stop();
|
||||
}
|
||||
delete this->m_hideScrollbarTimer;
|
||||
this->m_hideScrollbarTimer = nullptr;
|
||||
}
|
||||
delete this->m_lastItem;
|
||||
delete this->m_listItems;
|
||||
delete this->m_searchedItems;
|
||||
delete this->m_selectedItems;
|
||||
delete this->m_sortFuncList;
|
||||
delete this->m_isSortList;
|
||||
delete this->m_hideScrollbarTimer;
|
||||
}
|
||||
|
||||
void ProcessListWidget::setProcessSortFunctions(QList<SortFunction> *list, int currentSortIndex, bool isSort)
|
||||
|
@ -501,7 +504,7 @@ void ProcessListWidget::keyPressEvent(QKeyEvent *keyEvent)
|
|||
void ProcessListWidget::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||
{
|
||||
if (this->m_mouseDragScrollbar) {
|
||||
this->m_offSet = setOffset((mouseEvent->y() - getScrollbarHeight() / 2 - this->m_titleHeight) / (getTheScrollAreaHeight()) * this->getItemsTotalHeight());
|
||||
this->m_offSet = setOffset((mouseEvent->y() - getScrollbarHeight() / 2 - this->m_titleHeight) / (getTheScrollAreaHeight() * 1.0) * this->getItemsTotalHeight());
|
||||
repaint();
|
||||
}
|
||||
else if (mouseAtScrollArea(mouseEvent->x()) != this->m_mouseAtScrollArea) {
|
||||
|
@ -603,7 +606,7 @@ void ProcessListWidget::mousePressEvent(QMouseEvent *mouseEvent)
|
|||
this->m_mouseDragScrollbar = true;
|
||||
}
|
||||
else {
|
||||
this->m_offSet = setOffset((mouseEvent->y() - barHeight / 2 - this->m_titleHeight) / (getTheScrollAreaHeight()) * this->getItemsTotalHeight());
|
||||
this->m_offSet = setOffset((mouseEvent->y() - barHeight / 2 - this->m_titleHeight) / (getTheScrollAreaHeight() * 1.0) * this->getItemsTotalHeight());
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
@ -719,45 +722,34 @@ void ProcessListWidget::paintEvent(QPaintEvent *)
|
|||
int posX = 0;
|
||||
for (int itemWidth:titleItemsWidths) {
|
||||
if (itemWidth > 0) {
|
||||
painter.setOpacity(1);
|
||||
QFont font = painter.font();
|
||||
font.setPointSize(10);
|
||||
painter.setFont(font);
|
||||
//标题文字
|
||||
painter.setPen(QPen(QColor("#000000")));
|
||||
painter.drawText(QRect(posX + this->m_titlePadding, 0, itemWidth, this->m_titleHeight), Qt::AlignVCenter | Qt::AlignLeft, this->columnTitles[counter]);
|
||||
posX += itemWidth;
|
||||
if (counter < titleItemsWidths.size() - 1) {//垂直分割线
|
||||
painter.setOpacity(0.1);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect().x() + posX - 1, rect().y() + 5, 1, this->m_titleHeight - 5*2));
|
||||
painter.fillPath(separatorPath, QColor("#000000"));
|
||||
}
|
||||
|
||||
//标题文字右侧的排序箭头图标
|
||||
//标题文字左上方的排序箭头图标
|
||||
if (this->m_currentSortIndex == counter) {
|
||||
painter.setOpacity(1);
|
||||
int arrowX = rect().x() + posX - 2 - m_upArrowNormalPixmap.width() / m_upArrowNormalPixmap.devicePixelRatio();
|
||||
int arrowY = rect().y() + (this->m_titleHeight - m_downArrowNormalPixmap.height() / m_upArrowNormalPixmap.devicePixelRatio()) / 2;
|
||||
|
||||
// int arrowX = rect().x() + posX - 2 - m_upArrowPixmap.width() / m_upArrowPixmap.devicePixelRatio();
|
||||
// int arrowY = rect().y() + (this->m_titleHeight / m_upArrowPixmap.devicePixelRatio()) - m_downArrowPixmap.height() - 5;
|
||||
if (this->m_isSort) {
|
||||
if (this->m_titlePressColumn == this->m_currentSortIndex) {
|
||||
painter.drawPixmap(QPoint(arrowX, arrowY), m_downArrowPressPixmap);
|
||||
} else if (this->m_titleHoverColumn == this->m_currentSortIndex) {
|
||||
painter.drawPixmap(QPoint(arrowX, arrowY), m_downArrowHoverPixmap);
|
||||
} else {
|
||||
painter.drawPixmap(QPoint(arrowX, arrowY), m_downArrowNormalPixmap);
|
||||
}
|
||||
painter.drawPixmap(QPoint(rect().x() + posX + 5, rect().y() + 10), m_downArrowPixmap);
|
||||
} else {
|
||||
if (this->m_titlePressColumn == this->m_currentSortIndex) {
|
||||
painter.drawPixmap(QPoint(arrowX, arrowY), m_upArrowPressPixmap);
|
||||
} else if (this->m_titleHoverColumn == this->m_currentSortIndex) {
|
||||
painter.drawPixmap(QPoint(arrowX, arrowY), m_upArrowHoverPixmap);
|
||||
} else {
|
||||
painter.drawPixmap(QPoint(arrowX, arrowY), m_upArrowNormalPixmap);
|
||||
}
|
||||
painter.drawPixmap(QPoint(rect().x() + posX + 5, rect().y() + 10), m_upArrowPixmap);
|
||||
}
|
||||
}
|
||||
|
||||
//标题文字
|
||||
painter.setOpacity(1);
|
||||
QFont font = painter.font();
|
||||
// font.setPointSize(10);
|
||||
font.setPixelSize(12);
|
||||
painter.setFont(font);
|
||||
painter.setPen(QPen(QColor("#999999")));
|
||||
painter.drawText(QRect(posX + this->m_titlePadding, 0, itemWidth, this->m_titleHeight), Qt::AlignBottom | Qt::AlignLeft, this->columnTitles[counter]);
|
||||
posX += itemWidth;
|
||||
|
||||
if (counter < titleItemsWidths.size() - 1) {//垂直分割线
|
||||
painter.setOpacity(0.8);
|
||||
QPainterPath separatorPath;
|
||||
separatorPath.addRect(QRectF(rect().x() + posX - 1, rect().y() + 5, 1, this->m_titleHeight - 5));
|
||||
painter.fillPath(separatorPath, QColor("#e0e0e0"));
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
@ -793,7 +785,10 @@ void ProcessListWidget::paintEvent(QPaintEvent *)
|
|||
for (int titleItemWidth : titleItemsWidths) {
|
||||
if (titleItemWidth > 0) {
|
||||
painter.save();
|
||||
item->drawForeground(QRect(columnTitleX, title_Y + rowCounter * this->m_rowHeight - this->m_offSet, titleItemWidth, this->m_rowHeight), &painter, columnCounter, rowCounter, isSelect);
|
||||
if (columnCounter < titleItemsWidths.size() - 1)
|
||||
item->drawForeground(QRect(columnTitleX, title_Y + rowCounter * this->m_rowHeight - this->m_offSet, titleItemWidth, this->m_rowHeight), &painter, columnCounter, rowCounter, isSelect, true);
|
||||
else
|
||||
item->drawForeground(QRect(columnTitleX, title_Y + rowCounter * this->m_rowHeight - this->m_offSet, titleItemWidth, this->m_rowHeight), &painter, columnCounter, rowCounter, isSelect, false);
|
||||
painter.restore();
|
||||
columnTitleX += titleItemWidth;
|
||||
}
|
||||
|
@ -830,7 +825,7 @@ void ProcessListWidget::paintEvent(QPaintEvent *)
|
|||
paintScrollbar(&painter);
|
||||
} else if (this->m_origOffset != this->m_offSet) {
|
||||
paintScrollbar(&painter);
|
||||
startScrollbarHideTimer();
|
||||
readyToHideScrollbar();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -941,12 +936,12 @@ int ProcessListWidget::getTheScrollAreaHeight()
|
|||
|
||||
int ProcessListWidget::getScrollbarY()
|
||||
{
|
||||
return static_cast<int>((this->m_offSet / (this->getItemsTotalHeight())) * getTheScrollAreaHeight() + this->m_titleHeight);
|
||||
return static_cast<int>((this->m_offSet / (this->getItemsTotalHeight() * 1.0)) * getTheScrollAreaHeight() + this->m_titleHeight);
|
||||
}
|
||||
|
||||
int ProcessListWidget::getScrollbarHeight()
|
||||
{
|
||||
return std::max(static_cast<int>(getTheScrollAreaHeight() / (this->getItemsTotalHeight()) * rect().height()), this->m_rowHeight);
|
||||
return std::max(static_cast<int>(getTheScrollAreaHeight() / (this->getItemsTotalHeight() * 1.0) * rect().height()), 30);//30 is min height
|
||||
}
|
||||
|
||||
QList<ProcessListItem*> ProcessListWidget::getSearchedItems(QList<ProcessListItem*> items)
|
||||
|
@ -984,12 +979,16 @@ void ProcessListWidget::sortItemsByColumn(int column, bool isSort)
|
|||
}
|
||||
}
|
||||
|
||||
void ProcessListWidget::startScrollbarHideTimer()
|
||||
void ProcessListWidget::readyToHideScrollbar()
|
||||
{
|
||||
if (this->m_hideScrollbarTimer) {
|
||||
this->m_hideScrollbarTimer->stop();
|
||||
if (this->m_hideScrollbarTimer->isActive())
|
||||
this->m_hideScrollbarTimer->stop();
|
||||
}
|
||||
else {
|
||||
this->m_hideScrollbarTimer = new QTimer();
|
||||
this->m_hideScrollbarTimer->setSingleShot(true);
|
||||
connect(this->m_hideScrollbarTimer, SIGNAL(timeout()), this, SLOT(hideScrollbar()));
|
||||
}
|
||||
this->m_hideScrollbarTimer = new QTimer();
|
||||
connect(this->m_hideScrollbarTimer, SIGNAL(timeout()), this, SLOT(hideScrollbar()));
|
||||
this->m_hideScrollbarTimer->start(2000);
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
~ProcessListWidget();
|
||||
ProcessListWidget(QList<bool> toBeDisplayedColumns, QWidget *parent = 0);
|
||||
|
||||
void readyToHideScrollbar();
|
||||
|
||||
void setProcessSortFunctions(QList<SortFunction> *list, int sortColumn=-1, bool isSort=false);
|
||||
void setSearchFunction(SearchFunction func);
|
||||
void addItems(QList<ProcessListItem*> items);
|
||||
|
@ -72,7 +74,7 @@ public:
|
|||
QList<int> getTitleItemsWidths();
|
||||
|
||||
int setOffset(int offset);
|
||||
void startScrollbarHideTimer();
|
||||
|
||||
bool mouseAtScrollArea(int x);
|
||||
bool mouseAtTitleArea(int y);
|
||||
|
||||
|
@ -122,12 +124,8 @@ private:
|
|||
int m_titlePadding;
|
||||
int m_titlePressColumn;
|
||||
|
||||
QPixmap m_downArrowHoverPixmap;
|
||||
QPixmap m_downArrowNormalPixmap;
|
||||
QPixmap m_downArrowPressPixmap;
|
||||
QPixmap m_upArrowHoverPixmap;
|
||||
QPixmap m_upArrowNormalPixmap;
|
||||
QPixmap m_upArrowPressPixmap;
|
||||
QPixmap m_downArrowPixmap;
|
||||
QPixmap m_upArrowPixmap;
|
||||
};
|
||||
|
||||
#endif // PROCESSLISTWIDGET_H
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "propertiesdialog.h"
|
||||
#include "processworker.h"
|
||||
#include "../widgets/myimagebutton.h"
|
||||
#include "../widgets/mytristatebutton.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
@ -60,9 +60,9 @@ PropertiesDialog::PropertiesDialog(QWidget *parent, pid_t processId) : QDialog(p
|
|||
startTimeLayout = new QHBoxLayout();
|
||||
startTimeLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
closeButton = new MyImageButton();
|
||||
closeButton = new MyTristateButton();
|
||||
closeButton->setObjectName("CloseButton");
|
||||
connect(closeButton, &MyImageButton::clicked, this, [=] {
|
||||
connect(closeButton, &MyTristateButton::clicked, this, [=] {
|
||||
this->close();
|
||||
});
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <QTimer>
|
||||
|
||||
class QMouseEvent;
|
||||
class MyImageButton;
|
||||
class MyTristateButton;
|
||||
|
||||
//TODO: add timer to refresh
|
||||
|
||||
|
@ -58,7 +58,7 @@ protected:
|
|||
// void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
MyImageButton *closeButton;
|
||||
MyTristateButton *closeButton;
|
||||
QHBoxLayout *cmdlineLayout;
|
||||
QHBoxLayout *userLayout;
|
||||
QHBoxLayout *nameLayout;
|
||||
|
|
|
@ -58,7 +58,6 @@ SystemMonitor::SystemMonitor(QWidget *parent)
|
|||
proSettings->setIniCodec("UTF-8");
|
||||
|
||||
this->initTitleWidget();
|
||||
this->initToolBar();
|
||||
this->initPanelStack();
|
||||
this->initConnections();
|
||||
|
||||
|
@ -78,10 +77,6 @@ SystemMonitor::~SystemMonitor()
|
|||
delete m_titleWidget;
|
||||
m_titleWidget = nullptr;
|
||||
}
|
||||
if (m_toolBar) {
|
||||
delete m_toolBar;
|
||||
m_toolBar = nullptr;
|
||||
}
|
||||
if (process_dialog) {
|
||||
delete process_dialog;
|
||||
process_dialog = nullptr;
|
||||
|
@ -103,18 +98,14 @@ SystemMonitor::~SystemMonitor()
|
|||
void SystemMonitor::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
if (m_titleWidget) {
|
||||
m_titleWidget->resize(width(), TITLE_WIDGET_HEIGHT);
|
||||
m_titleWidget->resize(width(), MONITOR_TITLE_WIDGET_HEIGHT);
|
||||
if (e->oldSize() != e->size()) {
|
||||
emit m_titleWidget->updateMaxBtn();
|
||||
}
|
||||
}
|
||||
if (m_toolBar) {
|
||||
m_toolBar->resize(width(), TITLE_WIDGET_HEIGHT);
|
||||
m_toolBar->move(0, TITLE_WIDGET_HEIGHT);
|
||||
}
|
||||
if (m_sysMonitorStack) {
|
||||
m_sysMonitorStack->resize(width(), this->height() - TITLE_WIDGET_HEIGHT*2);
|
||||
m_sysMonitorStack->move(0, TITLE_WIDGET_HEIGHT*2);
|
||||
m_sysMonitorStack->resize(width(), this->height() - MONITOR_TITLE_WIDGET_HEIGHT);
|
||||
m_sysMonitorStack->move(0, MONITOR_TITLE_WIDGET_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +183,6 @@ void SystemMonitor::initPanelStack()
|
|||
process_dialog->getProcessView()->installEventFilter(this);
|
||||
connect(process_dialog, &ProcessDialog::changeColumnVisible, this, &SystemMonitor::recordVisibleColumn);
|
||||
connect(process_dialog, &ProcessDialog::changeSortStatus, this, &SystemMonitor::recordSortStatus);
|
||||
connect(m_toolBar, SIGNAL(activeWhoseProcessList(int)), process_dialog, SLOT(onActiveWhoseProcess(int)));
|
||||
|
||||
resources_dialog = new ResouresDialog;
|
||||
filesystem_dialog = new FileSystemDialog;
|
||||
|
@ -205,23 +195,16 @@ void SystemMonitor::initPanelStack()
|
|||
|
||||
void SystemMonitor::initTitleWidget()
|
||||
{
|
||||
m_titleWidget = new MonitorTitleWidget(this);
|
||||
m_titleWidget->resize(width(), TITLE_WIDGET_HEIGHT);
|
||||
m_titleWidget = new MonitorTitleWidget(proSettings, this);
|
||||
m_titleWidget->resize(width(), MONITOR_TITLE_WIDGET_HEIGHT);
|
||||
m_titleWidget->move(0, 0);
|
||||
}
|
||||
|
||||
void SystemMonitor::initToolBar()
|
||||
{
|
||||
m_toolBar = new ToolBar(proSettings, this);
|
||||
m_toolBar->resize(width(), TITLE_WIDGET_HEIGHT);
|
||||
m_toolBar->move(0, TITLE_WIDGET_HEIGHT);
|
||||
}
|
||||
|
||||
void SystemMonitor::initConnections()
|
||||
{
|
||||
connect(m_toolBar, SIGNAL(changePage(int)), this, SLOT(onChangePage(int)));
|
||||
connect(m_toolBar, SIGNAL(canelSearchEditFocus()), process_dialog, SLOT(focusProcessView()));
|
||||
connect(m_toolBar, SIGNAL(searchSignal(QString)), process_dialog, SLOT(onSearch(QString)), Qt::QueuedConnection);
|
||||
connect(m_titleWidget, SIGNAL(changePage(int)), this, SLOT(onChangePage(int)));
|
||||
connect(m_titleWidget, SIGNAL(canelSearchEditFocus()), process_dialog, SLOT(focusProcessView()));
|
||||
connect(m_titleWidget, SIGNAL(searchSignal(QString)), process_dialog, SLOT(onSearch(QString)), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void SystemMonitor::onChangePage(int index)
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#define SYSTEMMONITOR_H
|
||||
|
||||
#include "monitortitlewidget.h"
|
||||
#include "toolbar.h"
|
||||
#include "processdialog.h"
|
||||
#include "resourcesdialog.h"
|
||||
#include "filesystemdialog.h"
|
||||
|
@ -40,7 +39,6 @@ public:
|
|||
~SystemMonitor();
|
||||
|
||||
void initTitleWidget();
|
||||
void initToolBar();
|
||||
void initPanelStack();
|
||||
void initConnections();
|
||||
|
||||
|
@ -65,7 +63,7 @@ protected:
|
|||
private:
|
||||
QStackedWidget *m_sysMonitorStack = nullptr;
|
||||
MonitorTitleWidget *m_titleWidget = nullptr;
|
||||
ToolBar *m_toolBar = nullptr;
|
||||
// ToolBar *m_toolBar = nullptr;
|
||||
ProcessDialog *process_dialog = nullptr;
|
||||
ResouresDialog *resources_dialog = nullptr;
|
||||
FileSystemDialog *filesystem_dialog = nullptr;
|
||||
|
|
|
@ -36,7 +36,9 @@ HEADERS += \
|
|||
util.h \
|
||||
../../component/utils.h \
|
||||
../widgets/mydialog.h \
|
||||
../widgets/myimagebutton.h \
|
||||
../widgets/mytristatebutton.h \
|
||||
../widgets/myunderlinebutton.h \
|
||||
../widgets/myhoverbutton.h \
|
||||
propertiesdialog.h \
|
||||
processcategory.h \
|
||||
processdata.h \
|
||||
|
@ -44,8 +46,6 @@ HEADERS += \
|
|||
../widgets/myactiongroupitem.h \
|
||||
../widgets/myaction.h \
|
||||
monitortitlewidget.h \
|
||||
toolbar.h \
|
||||
../widgets/mytipimagebutton.h \
|
||||
resourcesdialog.h \
|
||||
filesystemdialog.h \
|
||||
diskitemlist.h \
|
||||
|
@ -69,15 +69,15 @@ SOURCES += \
|
|||
processworker.cpp \
|
||||
util.cpp \
|
||||
../widgets/mydialog.cpp \
|
||||
../widgets/myimagebutton.cpp \
|
||||
../widgets/mytristatebutton.cpp \
|
||||
../widgets/myunderlinebutton.cpp \
|
||||
../widgets/myhoverbutton.cpp \
|
||||
propertiesdialog.cpp \
|
||||
processcategory.cpp \
|
||||
../widgets/myactiongroup.cpp \
|
||||
../widgets/myactiongroupitem.cpp \
|
||||
../widgets/myaction.cpp \
|
||||
monitortitlewidget.cpp \
|
||||
toolbar.cpp \
|
||||
../widgets/mytipimagebutton.cpp \
|
||||
resourcesdialog.cpp \
|
||||
filesystemdialog.cpp \
|
||||
diskitemlist.cpp \
|
||||
|
|
|
@ -1,305 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "toolbar.h"
|
||||
#include "../widgets/myimagebutton.h"
|
||||
#include "../widgets/mytipimagebutton.h"
|
||||
#include "processcategory.h"
|
||||
#include "../widgets/mysearchedit.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include <QStyleFactory>
|
||||
|
||||
ToolBar::ToolBar(QSettings *settings, QWidget *parent)
|
||||
:QFrame(parent)
|
||||
,proSettings(settings)
|
||||
{
|
||||
installEventFilter(this);
|
||||
setMouseTracking(true);
|
||||
setFixedHeight(TITLE_WIDGET_HEIGHT);
|
||||
|
||||
m_topBorderColor = QColor(255, 255, 255, 153);
|
||||
// this->setAutoFillBackground(true);
|
||||
// QPalette palette;
|
||||
// palette.setColor(QPalette::Background, QColor("#0d87ca"));
|
||||
// this->setPalette(palette);
|
||||
|
||||
m_searchTimer = new QTimer(this);
|
||||
m_searchTimer->setSingleShot(true);
|
||||
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(onRefreshSearchResult()));
|
||||
|
||||
initWidgets();
|
||||
}
|
||||
|
||||
ToolBar::~ToolBar()
|
||||
{
|
||||
delete processLabel;
|
||||
delete m_searchEdit;
|
||||
delete m_cancelSearchBtn;
|
||||
delete processCategory;
|
||||
|
||||
if (m_searchTimer) {
|
||||
disconnect(m_searchTimer, SIGNAL(timeout()), this, SLOT(onRefreshSearchResult()));
|
||||
if(m_searchTimer->isActive()) {
|
||||
m_searchTimer->stop();
|
||||
}
|
||||
delete m_searchTimer;
|
||||
m_searchTimer = nullptr;
|
||||
}
|
||||
|
||||
//Segmentation fault
|
||||
QLayoutItem *child;
|
||||
while ((child = m_lLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
while ((child = m_mLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
while ((child = m_rLayout->takeAt(0)) != 0) {
|
||||
if (child->widget())
|
||||
child->widget()->deleteLater();
|
||||
delete child;
|
||||
}
|
||||
|
||||
delete m_layout;
|
||||
}
|
||||
|
||||
bool ToolBar::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
if (obj == this) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Escape) {
|
||||
m_searchEdit->clear();
|
||||
emit canelSearchEditFocus();
|
||||
}
|
||||
}
|
||||
else if (obj == m_searchEdit->getLineEdit()) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Tab) {
|
||||
emit canelSearchEditFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QFrame::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void ToolBar::setSearchEditFocus()
|
||||
{
|
||||
if (m_searchEdit->text() != "") {
|
||||
m_searchEdit->getLineEdit()->setFocus();
|
||||
} else {
|
||||
m_searchEdit->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void ToolBar::onRefreshSearchResult()
|
||||
{
|
||||
if (m_searchEdit->text() == searchTextCache) {
|
||||
emit this->searchSignal(searchTextCache);
|
||||
}
|
||||
}
|
||||
|
||||
void ToolBar::handleSearchTextChanged()
|
||||
{
|
||||
searchTextCache = m_searchEdit->text();
|
||||
|
||||
this->m_cancelSearchBtn->setVisible(!searchTextCache.isEmpty());
|
||||
|
||||
if (m_searchTimer->isActive()) {
|
||||
m_searchTimer->stop();
|
||||
}
|
||||
m_searchTimer->start(300);
|
||||
}
|
||||
|
||||
void ToolBar::onCancelSearchBtnClicked(bool b)
|
||||
{
|
||||
this->m_cancelSearchBtn->setVisible(false);
|
||||
m_searchEdit->clear();
|
||||
emit canelSearchEditFocus();
|
||||
}
|
||||
|
||||
void ToolBar::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
|
||||
QFrame::paintEvent(e);
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
const QColor tc(m_topBorderColor);
|
||||
int borderHeight = 1;
|
||||
QPainterPath tPath;
|
||||
tPath.moveTo(QPointF(x(), y() + borderHeight - 0.5));
|
||||
tPath.lineTo(QPointF(x() + width(), y() + borderHeight - 0.5));
|
||||
p.setPen(QPen(tc));
|
||||
p.drawPath(tPath);
|
||||
}
|
||||
|
||||
|
||||
void ToolBar::initLeftContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
m_lLayout = new QHBoxLayout(w);
|
||||
m_lLayout->setContentsMargins(6, 0, 0, 0);
|
||||
m_lLayout->setSpacing(0);
|
||||
|
||||
processLabel = new QLabel("");
|
||||
processLabel->setStyleSheet("QLabel { background-color : transparent; color : #505050; }");
|
||||
m_lLayout->addWidget(processLabel);
|
||||
|
||||
m_layout->addWidget(w, 1, Qt::AlignLeft);
|
||||
}
|
||||
|
||||
void ToolBar::initMiddleContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
m_mLayout = new QHBoxLayout(w);
|
||||
m_mLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mLayout->setSpacing(0);
|
||||
|
||||
MyTipImageButton *processButton = new MyTipImageButton();
|
||||
processButton->setCheckable(true);
|
||||
processButton->setChecked(true);
|
||||
processButton->setObjectName("ProcessBtn");
|
||||
|
||||
MyTipImageButton *resourcesButton = new MyTipImageButton();
|
||||
resourcesButton->setCheckable(true);
|
||||
resourcesButton->setChecked(false);
|
||||
resourcesButton->setObjectName("ResourcesBtn");
|
||||
|
||||
MyTipImageButton *disksButton = new MyTipImageButton();
|
||||
disksButton->setCheckable(true);
|
||||
disksButton->setChecked(false);
|
||||
disksButton->setObjectName("DisksBtn");
|
||||
|
||||
connect(processButton, &MyTipImageButton::clicked, this, [=] {
|
||||
emit this->changePage(0);
|
||||
processButton->setChecked(true);
|
||||
resourcesButton->setChecked(false);
|
||||
disksButton->setChecked(false);
|
||||
if (!m_searchEdit->isVisible())
|
||||
m_searchEdit->setVisible(true);
|
||||
if (!processCategory->isVisible())
|
||||
processCategory->setVisible(true);
|
||||
});
|
||||
connect(resourcesButton, &MyTipImageButton::clicked, this, [=] {
|
||||
emit this->changePage(1);
|
||||
processButton->setChecked(false);
|
||||
resourcesButton->setChecked(true);
|
||||
disksButton->setChecked(false);
|
||||
if (m_searchEdit->isVisible())
|
||||
m_searchEdit->setVisible(false);
|
||||
if (processCategory->isVisible())
|
||||
processCategory->setVisible(false);
|
||||
m_searchEdit->clear();
|
||||
emit canelSearchEditFocus();
|
||||
});
|
||||
connect(disksButton, &MyTipImageButton::clicked, this, [=] {
|
||||
emit this->changePage(2);
|
||||
processButton->setChecked(false);
|
||||
resourcesButton->setChecked(false);
|
||||
disksButton->setChecked(true);
|
||||
if (m_searchEdit->isVisible())
|
||||
m_searchEdit->setVisible(false);
|
||||
if (processCategory->isVisible())
|
||||
processCategory->setVisible(false);
|
||||
m_searchEdit->clear();
|
||||
emit canelSearchEditFocus();
|
||||
});
|
||||
processButton->setToolTip(tr("Processes"));
|
||||
resourcesButton->setToolTip(tr("Resources"));
|
||||
disksButton->setToolTip(tr("File Systems"));
|
||||
|
||||
m_mLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mLayout->setSpacing(10);
|
||||
m_mLayout->addStretch();
|
||||
m_mLayout->addWidget(processButton);
|
||||
m_mLayout->addWidget(resourcesButton);
|
||||
m_mLayout->addWidget(disksButton);
|
||||
m_mLayout->addStretch();
|
||||
|
||||
m_layout->addWidget(w);
|
||||
}
|
||||
|
||||
void ToolBar::initRightContent()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
m_rLayout = new QHBoxLayout(w);
|
||||
m_rLayout->setContentsMargins(0, 3, 6, 3);
|
||||
m_rLayout->setSpacing(5);
|
||||
|
||||
m_cancelSearchBtn = new QPushButton;
|
||||
m_cancelSearchBtn->setObjectName("blackButton");
|
||||
m_cancelSearchBtn->setText(tr("Cancel"));
|
||||
m_cancelSearchBtn->setFocusPolicy(Qt::NoFocus);
|
||||
m_cancelSearchBtn->setFixedSize(46, 25);
|
||||
m_cancelSearchBtn->setVisible(false);
|
||||
connect(m_cancelSearchBtn, SIGNAL(clicked(bool)), SLOT(onCancelSearchBtnClicked(bool)));
|
||||
|
||||
connect(m_searchEdit, &MySearchEdit::textChanged, this, &ToolBar::handleSearchTextChanged, Qt::QueuedConnection);
|
||||
m_rLayout->addWidget(m_searchEdit);
|
||||
m_rLayout->addWidget(m_cancelSearchBtn);
|
||||
|
||||
QString whose_processes = "user";
|
||||
proSettings->beginGroup("PROCESS");
|
||||
whose_processes = proSettings->value("WhoseProcesses", whose_processes).toString();
|
||||
proSettings->endGroup();
|
||||
int tabIndex = 1;
|
||||
if (whose_processes == "active") {
|
||||
tabIndex = 0;
|
||||
}
|
||||
else if (whose_processes == "all") {
|
||||
tabIndex = 2;
|
||||
}
|
||||
else {
|
||||
tabIndex = 1;
|
||||
}
|
||||
processCategory = new ProcessCategory(tabIndex);
|
||||
connect(processCategory, SIGNAL(activeWhoseProcessList(int)), this, SIGNAL(activeWhoseProcessList(int)));
|
||||
m_rLayout->addSpacing(10);
|
||||
m_rLayout->addWidget(processCategory, 0, Qt::AlignVCenter);
|
||||
m_layout->addWidget(w, 1, Qt::AlignRight);
|
||||
}
|
||||
|
||||
void ToolBar::initWidgets()
|
||||
{
|
||||
m_layout = new QHBoxLayout(this);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setSpacing(0);
|
||||
this->setLayout(m_layout);
|
||||
|
||||
m_searchEdit = new MySearchEdit();
|
||||
m_searchEdit->setFixedWidth(222);
|
||||
m_searchEdit->getLineEdit()->installEventFilter(this);
|
||||
|
||||
initLeftContent();
|
||||
initMiddleContent();
|
||||
initRightContent();
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TOOLBAR_H
|
||||
#define TOOLBAR_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QTimer>
|
||||
#include <QSettings>
|
||||
|
||||
class QHBoxLayout;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class ProcessCategory;
|
||||
class MySearchEdit;
|
||||
|
||||
class ToolBar : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ToolBar(QSettings *settings, QWidget *parent);
|
||||
~ToolBar();
|
||||
|
||||
void setSearchEditFocus();
|
||||
void initLeftContent();
|
||||
void initMiddleContent();
|
||||
void initRightContent();
|
||||
void initWidgets();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
bool eventFilter(QObject *, QEvent *event);
|
||||
|
||||
public slots:
|
||||
void onRefreshSearchResult();
|
||||
void handleSearchTextChanged();
|
||||
void onCancelSearchBtnClicked(bool b);
|
||||
|
||||
signals:
|
||||
void changePage(int index);
|
||||
void searchSignal(QString searchContent);
|
||||
void canelSearchEditFocus();
|
||||
void activeWhoseProcessList(int index);
|
||||
|
||||
private:
|
||||
QSettings *proSettings;
|
||||
QColor m_topBorderColor;
|
||||
MySearchEdit *m_searchEdit;
|
||||
QPushButton *m_cancelSearchBtn;
|
||||
QString searchTextCache;
|
||||
QTimer *m_searchTimer = nullptr;
|
||||
QLabel *processLabel;
|
||||
ProcessCategory *processCategory;
|
||||
QHBoxLayout *m_layout;
|
||||
QHBoxLayout *m_lLayout;
|
||||
QHBoxLayout *m_mLayout;
|
||||
QHBoxLayout *m_rLayout;
|
||||
};
|
||||
|
||||
#endif // TOOLBAR_H
|
|
@ -260,7 +260,8 @@ QString getNiceLevel(int nice)
|
|||
void setFontSize(QPainter &painter, int textSize)
|
||||
{
|
||||
QFont font = painter.font() ;
|
||||
font.setPointSize(textSize);
|
||||
font.setPixelSize(textSize);
|
||||
// font.setPointSize(textSize);
|
||||
painter.setFont(font);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
#define MONITOR_TITLE_WIDGET_HEIGHT 77
|
||||
#define TITLE_WIDGET_HEIGHT 39
|
||||
|
||||
using std::string;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "mydialog.h"
|
||||
#include "myimagebutton.h"
|
||||
#include "mytristatebutton.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QButtonGroup>
|
||||
|
@ -53,12 +53,12 @@ MyDialog::MyDialog(const QString &title, const QString &message, QWidget *parent
|
|||
topLayout->addLayout(contentLayout);
|
||||
|
||||
|
||||
closeButton = new MyImageButton(this);
|
||||
closeButton = new MyTristateButton(this);
|
||||
closeButton->setObjectName("CloseButton");
|
||||
// closeButton->setNormalPic(":/res/tool/close_normal.png");
|
||||
// closeButton->setHoverPic(":/res/tool/close_hover.png");
|
||||
// closeButton->setPressPic(":/res/tool/close_press.png");
|
||||
connect(closeButton, &MyImageButton::clicked, this, [=] {
|
||||
connect(closeButton, &MyTristateButton::clicked, this, [=] {
|
||||
this->close();
|
||||
});
|
||||
closeButton->setAttribute(Qt::WA_NoMousePropagation);
|
||||
|
|
|
@ -11,7 +11,7 @@ class QButtonGroup;
|
|||
class QLabel;
|
||||
class QCloseEvent;
|
||||
class QVBoxLayout;
|
||||
class MyImageButton;
|
||||
class MyTristateButton;
|
||||
|
||||
#include <QBoxLayout>
|
||||
|
||||
|
@ -59,7 +59,7 @@ private:
|
|||
QLabel* messageLabel;
|
||||
QLabel* titleLabel;
|
||||
|
||||
MyImageButton* closeButton = nullptr;
|
||||
MyTristateButton* closeButton = nullptr;
|
||||
QHBoxLayout *iconLayout;
|
||||
QVBoxLayout *contentLayout;
|
||||
QHBoxLayout *buttonLayout;
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
#include "myhoverbutton.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QEvent>
|
||||
|
||||
MyHoverButton::MyHoverButton(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
,m_state(Normal)
|
||||
,m_isChecked(false)
|
||||
{
|
||||
this->setStyleSheet("QLabel{background-color:transparent;}");
|
||||
}
|
||||
|
||||
MyHoverButton::~MyHoverButton()
|
||||
{
|
||||
}
|
||||
|
||||
void MyHoverButton::enterEvent(QEvent *event)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
|
||||
if (!m_isChecked){
|
||||
setState(Hover);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
//QLabel::enterEvent(event);
|
||||
}
|
||||
|
||||
void MyHoverButton::leaveEvent(QEvent *event)
|
||||
{
|
||||
if (!m_isChecked){
|
||||
setState(Normal);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
//QLabel::leaveEvent(event);
|
||||
}
|
||||
|
||||
void MyHoverButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
setState(Press);
|
||||
|
||||
event->accept();
|
||||
//QLabel::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void MyHoverButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!rect().contains(event->pos()))
|
||||
return;
|
||||
|
||||
m_isChecked = !m_isChecked;
|
||||
if (m_isChecked){
|
||||
setState(Checked);
|
||||
} else {
|
||||
setState(Normal);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
//QLabel::mouseReleaseEvent(event);
|
||||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
void MyHoverButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!rect().contains(event->pos())) {
|
||||
setState(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
void MyHoverButton::updateBackgroundColor()
|
||||
{
|
||||
switch (m_state) {
|
||||
case Hover:
|
||||
this->setStyleSheet("QLabel{background-color:#e0f4f9;}");
|
||||
break;
|
||||
case Press:
|
||||
this->setStyleSheet("QLabel{background-color:#e0f4f9;}");
|
||||
break;
|
||||
case Checked:
|
||||
this->setStyleSheet("QLabel{background-color:#e0f4f9;}");
|
||||
break;
|
||||
default:
|
||||
this->setStyleSheet("QLabel{background-color:transparent;}");
|
||||
break;
|
||||
}
|
||||
setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
void MyHoverButton::setState(MyHoverButton::HoverButtonState state)
|
||||
{
|
||||
if (m_state == state)
|
||||
return;
|
||||
|
||||
m_state = state;
|
||||
|
||||
updateBackgroundColor();
|
||||
}
|
||||
|
||||
void MyHoverButton::setChecked(bool flag)
|
||||
{
|
||||
m_isChecked = flag;
|
||||
if (m_isChecked){
|
||||
setState(Checked);
|
||||
} else {
|
||||
setState(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
bool MyHoverButton::isChecked()
|
||||
{
|
||||
return m_isChecked;
|
||||
}
|
||||
|
||||
void MyHoverButton::setPicture(const QString &picture)
|
||||
{
|
||||
setPixmap(QPixmap(picture));
|
||||
}
|
||||
|
||||
MyHoverButton::HoverButtonState MyHoverButton::getButtonState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef MYHOVERBUTTON_H
|
||||
#define MYHOVERBUTTON_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
|
||||
class MyHoverButton : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum HoverButtonState {Normal, Hover, Press, Checked};
|
||||
|
||||
public:
|
||||
MyHoverButton(QWidget * parent=0);
|
||||
~MyHoverButton();
|
||||
|
||||
void setChecked(bool flag);
|
||||
bool isChecked();
|
||||
void setPicture(const QString &picture);
|
||||
HoverButtonState getButtonState() const;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
void stateChanged();
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent * event) Q_DECL_OVERRIDE;
|
||||
void leaveEvent(QEvent * event) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void updateBackgroundColor();
|
||||
void setState(HoverButtonState state);
|
||||
|
||||
private:
|
||||
HoverButtonState m_state;
|
||||
bool m_isChecked;
|
||||
};
|
||||
|
||||
#endif // MYHOVERBUTTON_H
|
|
@ -12,17 +12,23 @@
|
|||
MySearchEdit::MySearchEdit(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
this->setStyleSheet("QFrame{border-radius: 4px;}");
|
||||
initInsideFrame();
|
||||
// this->setStyleSheet("QFrame{background-color:#00376a;border-radius:0px;}");
|
||||
this->setStyleSheet("QFrame{background-color:rgb(0, 55, 106, 127);border-radius:0px;}");
|
||||
|
||||
m_searchBtn = new QLabel;
|
||||
m_searchBtn->setStyleSheet("QLabel{background-color:transparent;margin: 2 -1 2 4 px;border-image:url(:/res/search.png);}");
|
||||
m_searchBtn->setStyleSheet("QLabel{background-color:transparent;border:none;background-image:url(:/res/search.png);}");
|
||||
m_searchBtn->setFixedSize(16, 16);
|
||||
m_clearBtn = new MyImageButton;
|
||||
|
||||
m_clearBtn = new MyTristateButton;
|
||||
m_clearBtn->setObjectName("ClearIcon");
|
||||
m_clearBtn->hide();
|
||||
|
||||
m_edit = new QLineEdit;
|
||||
m_edit->setStyleSheet("QLineEdit{background-color:transparent;border-radius:0px;color:#303030;padding-right:15px;padding-bottom: 3px;}");
|
||||
//m_edit->setPlaceholderText("enter process info");
|
||||
|
||||
m_placeHolder = new QLabel;
|
||||
m_placeHolder->setStyleSheet("QLabel{background-color:transparent;color:#808080;font-size:12px;margin: 2 0 0 0 px;} QLabel:hover{color:#ffffff;font-size:12px;}");
|
||||
|
||||
m_animation = new QPropertyAnimation(m_edit, "minimumWidth");
|
||||
|
||||
|
@ -31,25 +37,33 @@ MySearchEdit::MySearchEdit(QWidget *parent)
|
|||
m_edit->setFixedWidth(0);
|
||||
m_edit->installEventFilter(this);
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(m_insideFrame);
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->addStretch();
|
||||
layout->addWidget(m_searchBtn);
|
||||
layout->setAlignment(m_searchBtn, Qt::AlignCenter);
|
||||
layout->addWidget(m_placeHolder);
|
||||
layout->setAlignment(m_placeHolder, Qt::AlignCenter);
|
||||
layout->addWidget(m_edit);
|
||||
layout->setAlignment(m_edit, Qt::AlignCenter);
|
||||
// layout->addStretch();
|
||||
// layout->addWidget(m_searchBtn);
|
||||
// layout->setAlignment(m_searchBtn, Qt::AlignCenter);
|
||||
layout->addStretch();
|
||||
layout->addWidget(m_clearBtn);
|
||||
layout->setAlignment(m_clearBtn, Qt::AlignCenter);
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(3, 0, 3, 0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
setAutoFillBackground(true);
|
||||
// setAutoFillBackground(true);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
connect(m_clearBtn, &MyImageButton::clicked, m_edit, static_cast<void (QLineEdit::*)()>(&QLineEdit::setFocus));
|
||||
connect(m_clearBtn, &MyImageButton::clicked, this, &MySearchEdit::clear);
|
||||
connect(m_clearBtn, &MyTristateButton::clicked, m_edit, static_cast<void (QLineEdit::*)()>(&QLineEdit::setFocus));
|
||||
connect(m_clearBtn, &MyTristateButton::clicked, this, &MySearchEdit::clearEdit);
|
||||
connect(m_edit, &QLineEdit::textChanged, [this] {m_clearBtn->setVisible(!m_edit->text().isEmpty());});
|
||||
connect(m_edit, &QLineEdit::textChanged, this, &MySearchEdit::textChanged, Qt::DirectConnection);
|
||||
// connect(m_edit, &QLineEdit::textChanged, this, [=] {
|
||||
// emit this->textChanged();
|
||||
// });
|
||||
}
|
||||
|
||||
MySearchEdit::~MySearchEdit()
|
||||
|
@ -62,13 +76,19 @@ const QString MySearchEdit::text() const
|
|||
return m_edit->text();
|
||||
}
|
||||
|
||||
void MySearchEdit::clearEdit()
|
||||
{
|
||||
m_edit->clear();
|
||||
// this->setStyleSheet("QFrame{background-color:#00376a;border-radius:0px;}");
|
||||
this->setStyleSheet("QFrame{background-color:rgb(0, 55, 106, 127);border-radius:0px;}");
|
||||
}
|
||||
|
||||
void MySearchEdit::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return QFrame::mousePressEvent(event);
|
||||
|
||||
setEditFocus();
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
|
@ -87,37 +107,34 @@ bool MySearchEdit::eventFilter(QObject *object, QEvent *event)
|
|||
m_animation->setEndValue(0);
|
||||
m_animation->setEasingCurve(m_hideCurve);
|
||||
m_animation->start();
|
||||
connect(m_animation, &QPropertyAnimation::finished, m_placeHolder, &QLabel::show);
|
||||
}
|
||||
}
|
||||
|
||||
return QFrame::eventFilter(object, event);
|
||||
}
|
||||
|
||||
QLineEdit *MySearchEdit::getLineEdit() const
|
||||
{
|
||||
return m_edit;
|
||||
}
|
||||
|
||||
void MySearchEdit::setEditFocus()
|
||||
{
|
||||
if (!m_placeHolder->isVisible()) {
|
||||
return;
|
||||
}
|
||||
disconnect(m_animation, &QPropertyAnimation::finished, m_placeHolder, &QLabel::show);
|
||||
m_animation->stop();
|
||||
m_animation->setStartValue(0);
|
||||
m_animation->setEndValue(m_size.width() - m_searchBtn->width() - 6);
|
||||
m_animation->setEasingCurve(m_showCurve);
|
||||
m_animation->start();
|
||||
|
||||
m_placeHolder->hide();
|
||||
m_edit->setFocus();
|
||||
// this->setStyleSheet("QFrame{background-color:#00376a;border:1px solid #47ccf3;border-radius:0px;}");
|
||||
this->setStyleSheet("QFrame{background-color:rgb(0, 55, 106, 127);border:1px solid #47ccf3;border-radius:0px;}");
|
||||
}
|
||||
|
||||
void MySearchEdit::initInsideFrame()
|
||||
|
||||
QLineEdit *MySearchEdit::getLineEdit() const
|
||||
{
|
||||
m_insideFrame = new QFrame(this);
|
||||
m_insideFrame->raise();
|
||||
m_insideFrame->setStyleSheet("QFrame{background-color: white;border: 1px solid;border-radius: 4px;border-color: rgba(0, 0, 0, 0.08);}");
|
||||
QHBoxLayout *insideLayout = new QHBoxLayout(this);
|
||||
insideLayout->setContentsMargins(0, 0, 0, 1);
|
||||
insideLayout->setSpacing(0);
|
||||
insideLayout->addWidget(m_insideFrame);
|
||||
return m_edit;
|
||||
}
|
||||
|
||||
void MySearchEdit::resizeEvent(QResizeEvent *event)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <QPropertyAnimation>
|
||||
#include <QLabel>
|
||||
|
||||
#include "myimagebutton.h"
|
||||
#include "mytristatebutton.h"
|
||||
|
||||
class MySearchEdit : public QFrame
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ public:
|
|||
explicit MySearchEdit(QWidget *parent = 0);
|
||||
~MySearchEdit();
|
||||
|
||||
void initInsideFrame();
|
||||
void setPlaceHolder(const QString &text) {m_placeHolder->setText(text);}
|
||||
QSize sizeHint() const {return m_size;}
|
||||
QSize minimumSizeHint() const {return m_size;}
|
||||
const QString text() const;
|
||||
|
@ -25,7 +25,7 @@ public:
|
|||
public slots:
|
||||
void setEditFocus();
|
||||
void setText(const QString & text) {if (m_edit) m_edit->setText(text);}
|
||||
inline void clear() {m_edit->clear();}
|
||||
void clearEdit();
|
||||
|
||||
signals:
|
||||
void textChanged();
|
||||
|
@ -41,8 +41,8 @@ private:
|
|||
QSize m_size;
|
||||
QLineEdit *m_edit;
|
||||
QLabel *m_searchBtn;
|
||||
MyImageButton *m_clearBtn;
|
||||
QFrame *m_insideFrame = NULL;
|
||||
QLabel *m_placeHolder;
|
||||
MyTristateButton *m_clearBtn;
|
||||
QPropertyAnimation *m_animation;
|
||||
QEasingCurve m_showCurve = QEasingCurve::OutCubic;
|
||||
QEasingCurve m_hideCurve = QEasingCurve::InCubic;
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
#include "mytipimagebutton.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDebug>
|
||||
#include <QHBoxLayout>
|
||||
#include <QTimer>
|
||||
#include <QHelpEvent>
|
||||
|
||||
MyTipImageButton::MyTipImageButton(QWidget *parent)
|
||||
: MyImageButton(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MyTipImageButton::event(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::ToolTip) {
|
||||
if (QHelpEvent *he = static_cast<QHelpEvent *>(e)) {
|
||||
showTooltip(he->globalPos());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (e->type() == QEvent::Leave) {
|
||||
emit mouseLeave();
|
||||
MyImageButton::leaveEvent(e);
|
||||
}
|
||||
else if (e->type() == QEvent::MouseButtonPress) {
|
||||
emit mouseLeave();
|
||||
|
||||
}
|
||||
|
||||
return MyImageButton::event(e);
|
||||
}
|
||||
|
||||
void MyTipImageButton::enterEvent(QEvent *e)
|
||||
{
|
||||
if (isEnabled()) {
|
||||
MyImageButton::enterEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void MyTipImageButton::showTooltip(const QPoint &gPos)
|
||||
{
|
||||
if (toolTip().trimmed().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFrame *tf = new QFrame();
|
||||
tf->setStyleSheet(this->styleSheet());
|
||||
tf->setWindowFlags(Qt::ToolTip);
|
||||
tf->setAttribute(Qt::WA_TranslucentBackground);
|
||||
QLabel *tl = new QLabel(tf);
|
||||
tl->setObjectName("TooltipLabel");
|
||||
tl->setText(toolTip());
|
||||
QHBoxLayout *layout = new QHBoxLayout(tf);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(tl);
|
||||
|
||||
tf->show();
|
||||
QRect dr = qApp->desktop()->geometry();
|
||||
int y = gPos.y() + tf->height();
|
||||
if (y > dr.y() + dr.height()) {
|
||||
y = gPos.y() - tf->height() - 10;
|
||||
}
|
||||
tf->move(gPos.x() - tf->width()/3, y - tf->height()/3);
|
||||
|
||||
QTimer::singleShot(5000, tf, SLOT(deleteLater()));
|
||||
|
||||
connect(this, &MyTipImageButton::mouseLeave, tf, &QFrame::deleteLater);
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef MYTIPIMAGEBUTTON_H
|
||||
#define MYTIPIMAGEBUTTON_H
|
||||
|
||||
#include <QEvent>
|
||||
#include <QLabel>
|
||||
|
||||
#include "myimagebutton.h"
|
||||
|
||||
class MyTipImageButton : public MyImageButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MyTipImageButton(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void mouseLeave();
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *e) Q_DECL_OVERRIDE;
|
||||
bool event(QEvent *e) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void showTooltip(const QPoint &gPos);
|
||||
};
|
||||
|
||||
#endif // MYTIPIMAGEBUTTON_H
|
|
@ -1,21 +1,20 @@
|
|||
#include "myimagebutton.h"
|
||||
#include "mytristatebutton.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QEvent>
|
||||
|
||||
|
||||
MyImageButton::MyImageButton(QWidget *parent)
|
||||
MyTristateButton::MyTristateButton(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
{
|
||||
setCheckable(false);//setCheckable(true);
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
MyImageButton::~MyImageButton()
|
||||
MyTristateButton::~MyTristateButton()
|
||||
{
|
||||
}
|
||||
|
||||
void MyImageButton::enterEvent(QEvent *event)
|
||||
void MyTristateButton::enterEvent(QEvent *event)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
|
||||
|
@ -27,7 +26,7 @@ void MyImageButton::enterEvent(QEvent *event)
|
|||
//QLabel::enterEvent(event);
|
||||
}
|
||||
|
||||
void MyImageButton::leaveEvent(QEvent *event)
|
||||
void MyTristateButton::leaveEvent(QEvent *event)
|
||||
{
|
||||
if (!m_isChecked){
|
||||
setState(Normal);
|
||||
|
@ -37,7 +36,7 @@ void MyImageButton::leaveEvent(QEvent *event)
|
|||
//QLabel::leaveEvent(event);
|
||||
}
|
||||
|
||||
void MyImageButton::mousePressEvent(QMouseEvent *event)
|
||||
void MyTristateButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
@ -48,7 +47,7 @@ void MyImageButton::mousePressEvent(QMouseEvent *event)
|
|||
//QLabel::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void MyImageButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
void MyTristateButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!rect().contains(event->pos()))
|
||||
return;
|
||||
|
@ -71,14 +70,14 @@ void MyImageButton::mouseReleaseEvent(QMouseEvent *event)
|
|||
emit clicked();
|
||||
}
|
||||
|
||||
void MyImageButton::mouseMoveEvent(QMouseEvent *event)
|
||||
void MyTristateButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!m_isCheckable && !rect().contains(event->pos())) {
|
||||
setState(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
void MyImageButton::updateIcon()
|
||||
void MyTristateButton::updateIcon()
|
||||
{
|
||||
switch (m_state) {
|
||||
case Hover: if (!m_hoverPic.isEmpty()) setPixmap(QPixmap(m_hoverPic)); break;
|
||||
|
@ -88,11 +87,9 @@ void MyImageButton::updateIcon()
|
|||
}
|
||||
|
||||
setAlignment(Qt::AlignCenter);
|
||||
|
||||
emit stateChanged();
|
||||
}
|
||||
|
||||
void MyImageButton::setState(MyImageButton::ButtonState state)
|
||||
void MyTristateButton::setState(MyTristateButton::ButtonState state)
|
||||
{
|
||||
if (m_state == state)
|
||||
return;
|
||||
|
@ -102,7 +99,7 @@ void MyImageButton::setState(MyImageButton::ButtonState state)
|
|||
updateIcon();
|
||||
}
|
||||
|
||||
void MyImageButton::setCheckable(bool flag)
|
||||
void MyTristateButton::setCheckable(bool flag)
|
||||
{
|
||||
m_isCheckable = flag;
|
||||
|
||||
|
@ -111,7 +108,7 @@ void MyImageButton::setCheckable(bool flag)
|
|||
}
|
||||
}
|
||||
|
||||
void MyImageButton::setChecked(bool flag)
|
||||
void MyTristateButton::setChecked(bool flag)
|
||||
{
|
||||
if (m_isCheckable == false){
|
||||
return;
|
||||
|
@ -125,41 +122,41 @@ void MyImageButton::setChecked(bool flag)
|
|||
}
|
||||
}
|
||||
|
||||
bool MyImageButton::isChecked()
|
||||
bool MyTristateButton::isChecked()
|
||||
{
|
||||
return m_isChecked;
|
||||
}
|
||||
|
||||
bool MyImageButton::isCheckable()
|
||||
bool MyTristateButton::isCheckable()
|
||||
{
|
||||
return m_isCheckable;
|
||||
}
|
||||
|
||||
void MyImageButton::setNormalPic(const QString &normalPicPixmap)
|
||||
void MyTristateButton::setNormalPic(const QString &normalPicPixmap)
|
||||
{
|
||||
m_normalPic = normalPicPixmap;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void MyImageButton::setHoverPic(const QString &hoverPicPixmap)
|
||||
void MyTristateButton::setHoverPic(const QString &hoverPicPixmap)
|
||||
{
|
||||
m_hoverPic = hoverPicPixmap;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void MyImageButton::setPressPic(const QString &pressPicPixmap)
|
||||
void MyTristateButton::setPressPic(const QString &pressPicPixmap)
|
||||
{
|
||||
m_pressPic = pressPicPixmap;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void MyImageButton::setCheckedPic(const QString &checkedPicPixmap)
|
||||
void MyTristateButton::setCheckedPic(const QString &checkedPicPixmap)
|
||||
{
|
||||
m_checkedPic = checkedPicPixmap;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
MyImageButton::ButtonState MyImageButton::getButtonState() const
|
||||
MyTristateButton::ButtonState MyTristateButton::getButtonState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef MYIMAGEBUTTON_H
|
||||
#define MYIMAGEBUTTON_H
|
||||
#ifndef MYTRISTATEBUTTON_H
|
||||
#define MYTRISTATEBUTTON_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
|
||||
class MyImageButton : public QLabel
|
||||
class MyTristateButton : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString normalPic READ getNormalPic WRITE setNormalPic DESIGNABLE true)
|
||||
|
@ -15,9 +15,9 @@ class MyImageButton : public QLabel
|
|||
Q_PROPERTY(QString checkedPic READ getCheckedPic WRITE setCheckedPic DESIGNABLE true)
|
||||
|
||||
public:
|
||||
MyImageButton(QWidget * parent=0);
|
||||
MyTristateButton(QWidget * parent=0);
|
||||
|
||||
~MyImageButton();
|
||||
~MyTristateButton();
|
||||
|
||||
void setChecked(bool flag);
|
||||
void setCheckable(bool flag);
|
||||
|
@ -63,4 +63,4 @@ private:
|
|||
QString m_checkedPic;
|
||||
};
|
||||
|
||||
#endif // MYIMAGEBUTTON_H
|
||||
#endif // MYTRISTATEBUTTON_H
|
|
@ -0,0 +1,150 @@
|
|||
#include "myunderlinebutton.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QEvent>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
||||
MyUnderLineButton::MyUnderLineButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
,m_state(Normal)
|
||||
,m_isChecked(false)
|
||||
{
|
||||
this->setFixedSize(80, 30);
|
||||
|
||||
m_textLabel = new QLabel;
|
||||
m_textLabel->setStyleSheet("QLabel{background-color:transparent;color:#ffffff; font-size:12px;text-align:center;}");
|
||||
|
||||
m_underlineLabel = new QLabel;
|
||||
m_underlineLabel->setFixedSize(52, 2);
|
||||
m_underlineLabel->setStyleSheet("QLabel{background-color:#ffffff;}");
|
||||
m_underlineLabel->hide();
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setContentsMargins(0,5,0,5);
|
||||
|
||||
m_layout->addWidget(m_textLabel, 0, Qt::AlignTop | Qt::AlignHCenter);
|
||||
m_layout->addWidget(m_underlineLabel, 0, Qt::AlignBottom | Qt::AlignHCenter);
|
||||
}
|
||||
|
||||
MyUnderLineButton::~MyUnderLineButton()
|
||||
{
|
||||
delete m_textLabel;
|
||||
delete m_underlineLabel;
|
||||
}
|
||||
|
||||
void MyUnderLineButton::enterEvent(QEvent *event)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
|
||||
if (!m_isChecked){
|
||||
setState(Hover);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
//QWidget::enterEvent(event);
|
||||
}
|
||||
|
||||
void MyUnderLineButton::leaveEvent(QEvent *event)
|
||||
{
|
||||
if (!m_isChecked){
|
||||
setState(Normal);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
//QWidget::leaveEvent(event);
|
||||
}
|
||||
|
||||
void MyUnderLineButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
setState(Press);
|
||||
|
||||
event->accept();
|
||||
//QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void MyUnderLineButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!rect().contains(event->pos()))
|
||||
return;
|
||||
|
||||
m_isChecked = !m_isChecked;
|
||||
if (m_isChecked){
|
||||
setState(Checked);
|
||||
} else {
|
||||
setState(Normal);
|
||||
}
|
||||
|
||||
event->accept();
|
||||
//QWidget::mouseReleaseEvent(event);
|
||||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
void MyUnderLineButton::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!rect().contains(event->pos())) {
|
||||
setState(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
void MyUnderLineButton::updateStyleSheet()
|
||||
{
|
||||
switch (m_state) {
|
||||
case Hover:
|
||||
m_textLabel->setStyleSheet("QLabel{background-color:transparent;color:#ffffff; font-size:12px;text-align:center;font-weight:bold;}");
|
||||
m_underlineLabel->hide();
|
||||
break;
|
||||
case Press:
|
||||
m_textLabel->setStyleSheet("QLabel{background-color:transparent;color:#ffffff; font-size:12px;text-align:center;font-weight:bold;}");
|
||||
m_underlineLabel->hide();
|
||||
break;
|
||||
case Checked:
|
||||
m_textLabel->setStyleSheet("QLabel{background-color:transparent;color:#ffffff; font-size:12px;text-align:center;font-weight:bold;}");
|
||||
m_underlineLabel->show();
|
||||
break;
|
||||
default:
|
||||
m_textLabel->setStyleSheet("QLabel{background-color:transparent;color:#ffffff; font-size:12px;text-align:center;}");
|
||||
m_underlineLabel->hide();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MyUnderLineButton::setState(MyUnderLineButton::UnderLineButtonState state)
|
||||
{
|
||||
if (m_state == state)
|
||||
return;
|
||||
|
||||
m_state = state;
|
||||
|
||||
updateStyleSheet();
|
||||
}
|
||||
|
||||
void MyUnderLineButton::setChecked(bool flag)
|
||||
{
|
||||
m_isChecked = flag;
|
||||
if (m_isChecked){
|
||||
setState(Checked);
|
||||
} else {
|
||||
setState(Normal);
|
||||
}
|
||||
}
|
||||
|
||||
bool MyUnderLineButton::isChecked()
|
||||
{
|
||||
return m_isChecked;
|
||||
}
|
||||
|
||||
void MyUnderLineButton::setName(const QString &name)
|
||||
{
|
||||
this->m_textLabel->setText(name);
|
||||
}
|
||||
|
||||
MyUnderLineButton::UnderLineButtonState MyUnderLineButton::getButtonState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef MYUNDERLINEBUTTON_H
|
||||
#define MYUNDERLINEBUTTON_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
|
||||
class QVBoxLayout;
|
||||
|
||||
class MyUnderLineButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum UnderLineButtonState {Normal, Hover, Press, Checked};
|
||||
|
||||
public:
|
||||
MyUnderLineButton(QWidget * parent=0);
|
||||
~MyUnderLineButton();
|
||||
|
||||
void setChecked(bool flag);
|
||||
bool isChecked();
|
||||
void setName(const QString &name);
|
||||
UnderLineButtonState getButtonState() const;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *event) Q_DECL_OVERRIDE;
|
||||
void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void updateStyleSheet();
|
||||
void setState(UnderLineButtonState state);
|
||||
|
||||
private:
|
||||
UnderLineButtonState m_state;
|
||||
bool m_isChecked;
|
||||
QLabel *m_textLabel = nullptr;
|
||||
QLabel *m_underlineLabel = nullptr;
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
};
|
||||
|
||||
#endif // MYUNDERLINEBUTTON_H
|
|
@ -193,12 +193,6 @@
|
|||
<file>res/camera-error.png</file>
|
||||
<file>res/catch-disable.png</file>
|
||||
<file>res/kylin-assistant.png</file>
|
||||
<file>res/arrow_up_hover.png</file>
|
||||
<file>res/arrow_up_normal.png</file>
|
||||
<file>res/arrow_up_press.png</file>
|
||||
<file>res/arrow_down_hover.png</file>
|
||||
<file>res/arrow_down_normal.png</file>
|
||||
<file>res/arrow_down_press.png</file>
|
||||
<file>res/tool/min_hover.png</file>
|
||||
<file>res/tool/min_normal.png</file>
|
||||
<file>res/tool/min_press.png</file>
|
||||
|
@ -227,6 +221,8 @@
|
|||
<file>res/user_proc.png</file>
|
||||
<file>res/active_proc.png</file>
|
||||
<file>res/all_proc.png</file>
|
||||
<file>res/arrow_down.png</file>
|
||||
<file>res/arrow_up.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/sys">
|
||||
<file>res/sysBtn/close_button.png</file>
|
||||
|
|
After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
|
@ -753,81 +753,39 @@ QLabel#TooltipLabel {
|
|||
font-weight: light;
|
||||
}
|
||||
|
||||
MyImageButton#ClearIcon {
|
||||
MyTristateButton#ClearIcon {
|
||||
background-color:transparent;
|
||||
qproperty-normalPic: url(:/res/delete.png);
|
||||
qproperty-hoverPic: url(:/res/delete.png);
|
||||
qproperty-pressPic: url(:/res/delete.png);
|
||||
}
|
||||
|
||||
MyImageButton#DiskDetailButton {
|
||||
MyTristateButton#DiskDetailButton {
|
||||
qproperty-normalPic: url(:/res/tool/arrow_right.png);
|
||||
qproperty-hoverPic: url(:/res/tool/arrow_right.png);
|
||||
qproperty-pressPic: url(:/res/tool/arrow_right.png);
|
||||
}
|
||||
|
||||
MyImageButton#CloseButton {
|
||||
MyTristateButton#CloseButton {
|
||||
qproperty-normalPic: url(:/res/tool/close_normal.png);
|
||||
qproperty-hoverPic: url(:/res/tool/close_hover.png);
|
||||
qproperty-pressPic: url(:/res/tool/close_press.png);
|
||||
}
|
||||
|
||||
MyImageButton#MinButton {
|
||||
MyTristateButton#MinButton {
|
||||
qproperty-normalPic: url(:/res/tool/min_normal.png);
|
||||
qproperty-hoverPic: url(:/res/tool/min_hover.png);
|
||||
qproperty-pressPic: url(:/res/tool/min_press.png);
|
||||
}
|
||||
|
||||
MyImageButton#MaxButton {
|
||||
MyTristateButton#MaxButton {
|
||||
qproperty-normalPic: url(:/res/tool/max_normal.png);
|
||||
qproperty-hoverPic: url(:/res/tool/max_hover.png);
|
||||
qproperty-pressPic: url(:/res/tool/max_press.png);
|
||||
}
|
||||
|
||||
MyImageButton#UnMaxButton {
|
||||
MyTristateButton#UnMaxButton {
|
||||
qproperty-normalPic: url(:/res/tool/unmax_normal.png);
|
||||
qproperty-hoverPic: url(:/res/tool/unmax_hover.png);
|
||||
qproperty-pressPic: url(:/res/tool/unmax_press.png);
|
||||
}
|
||||
|
||||
MyTipImageButton#ProcessBtn {
|
||||
qproperty-normalPic: url(:/res/browser_logo_gray.png);
|
||||
qproperty-hoverPic: url(:/res/browser_logo.png);
|
||||
qproperty-pressPic: url(:/res/browser_logo.png);
|
||||
qproperty-checkedPic: url(:/res/browser_logo.png);
|
||||
}
|
||||
|
||||
MyTipImageButton#ResourcesBtn {
|
||||
qproperty-normalPic: url(:/res/cache_logo_gray.png);
|
||||
qproperty-hoverPic: url(:/res/cache_logo.png);
|
||||
qproperty-pressPic: url(:/res/cache_logo.png);
|
||||
qproperty-checkedPic: url(:/res/cache_logo.png);
|
||||
}
|
||||
|
||||
MyTipImageButton#DisksBtn {
|
||||
qproperty-normalPic: url(:/res/cookie_logo_gray.png);
|
||||
qproperty-hoverPic: url(:/res/cookie_logo.png);
|
||||
qproperty-pressPic: url(:/res/cookie_logo.png);
|
||||
qproperty-checkedPic: url(:/res/cookie_logo.png);
|
||||
}
|
||||
|
||||
MyImageButton#ActiveProcessBtn {
|
||||
qproperty-normalPic: url(:/res/active_proc.png);
|
||||
qproperty-hoverPic: url(:/res/active_proc.png);
|
||||
qproperty-pressPic: url(:/res/active_proc.png);
|
||||
qproperty-checkedPic: url(:/res/active_proc.png);
|
||||
}
|
||||
|
||||
MyImageButton#UserProcessBtn {
|
||||
qproperty-normalPic: url(:/res/user_proc.png);
|
||||
qproperty-hoverPic: url(:/res/user_proc.png);
|
||||
qproperty-pressPic: url(:/res/user_proc.png);
|
||||
qproperty-checkedPic: url(:/res/user_proc.png);
|
||||
}
|
||||
|
||||
MyImageButton#AllProcessBtn {
|
||||
qproperty-normalPic: url(:/res/all_proc.png);
|
||||
qproperty-hoverPic: url(:/res/all_proc.png);
|
||||
qproperty-pressPic: url(:/res/all_proc.png);
|
||||
qproperty-checkedPic: url(:/res/all_proc.png);
|
||||
}
|
||||
|
|