-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I0e4b87e917048a69be9985e55a0013b270ceb7fb
- Loading branch information
Showing
17 changed files
with
604 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ debug | |
release | ||
build* | ||
|
||
*.pro.user* | ||
*.user* | ||
*.qm | ||
|
||
misc/*/deepin-toggle-desktop.desktop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.7) | ||
|
||
project(dmemory-warning-dialog | ||
VERSION 1.0.0) | ||
|
||
set(BIN_NAME dmemory-warning-dialog) | ||
#set(CMAKE_VERBOSE_MAKEFILE ON) | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
set(CMAKE_CXX_FLAGS -Wall) | ||
|
||
if (NOT (${CMAKE_BUILD_TYPE} MATCHES "Debug")) | ||
set(CMAKE_CXX_FLAGS -O3) | ||
endif () | ||
|
||
# Sources files | ||
file(GLOB SRCS "src/*.h" "src/*.cpp") | ||
|
||
# Find the library | ||
find_package(PkgConfig REQUIRED) | ||
find_package(Qt5 REQUIRED COMPONENTS Widgets Concurrent X11Extras DBus) | ||
find_package(Dtk REQUIRED COMPONENTS Widget) | ||
|
||
pkg_check_modules(XLIBS REQUIRED x11) | ||
|
||
# driver-manager | ||
add_executable(${BIN_NAME} ${SRCS}) | ||
target_include_directories(${BIN_NAME} PUBLIC ${XLIBS_INCLUDE_DIRS} ${Qt5X11Extras_INCLUDE_DIRS}) | ||
target_link_libraries(${BIN_NAME} PRIVATE | ||
${DtkWidget_LIBRARIES} | ||
${Qt5Widgets_LIBRARIES} | ||
${Qt5Concurrent_LIBRARIES} | ||
${Qt5DBus_LIBRARIES} | ||
${Qt5X11Extras_LIBRARIES} | ||
${XLIBS_LIBRARIES} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
QT += core gui widgets dbus x11extras | ||
|
||
TARGET = dmemory-warning-dialog | ||
TEMPLATE = app | ||
|
||
CONFIG += c++14 link_pkgconfig | ||
PKGCONFIG += dtkwidget | ||
|
||
HEADERS += \ | ||
src/buttondelegate.h \ | ||
src/dmemorywarningdialog.h \ | ||
src/processinfodelegate.h \ | ||
src/processinfomanager.h \ | ||
src/processinfomodel.h \ | ||
src/processinfotable.h | ||
|
||
SOURCES += \ | ||
src/buttondelegate.cpp \ | ||
src/dmemorywarningdialog.cpp \ | ||
src/main.cpp \ | ||
src/processinfodelegate.cpp \ | ||
src/processinfomanager.cpp \ | ||
src/processinfomodel.cpp \ | ||
src/processinfotable.cpp | ||
|
||
target.path = /usr/bin | ||
INSTALLS += target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "buttondelegate.h" | ||
#include "processinfomodel.h" | ||
|
||
#include <QApplication> | ||
#include <QProcess> | ||
#include <QDebug> | ||
|
||
void terminate(const QStringList &pidList) | ||
{ | ||
for (const auto &pid : pidList) | ||
QProcess::startDetached("kill", QStringList() << pid); | ||
} | ||
|
||
ButtonDelegate::ButtonDelegate(QObject *parent) | ||
: QItemDelegate(parent) | ||
{ | ||
|
||
} | ||
|
||
void ButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
{ | ||
QStyleOptionButton button; | ||
button.rect = option.rect.marginsRemoved(QMargins(6, 6, 6, 6)); | ||
button.text = index.data().toString(); | ||
button.state = QStyle::State_Enabled; | ||
if (index.data(ProcessInfoModel::StateRole).toBool()) | ||
button.state |= QStyle::State_Sunken | QStyle::State_Active; | ||
|
||
QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter); | ||
} | ||
|
||
bool ButtonDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) | ||
{ | ||
Q_UNUSED(option); | ||
|
||
switch (event->type()) | ||
{ | ||
case QEvent::MouseButtonPress: | ||
model->setData(index, QVariant(), ProcessInfoModel::StateRole); | ||
break; | ||
case QEvent::MouseButtonRelease: | ||
terminate(index.data(ProcessInfoModel::PidListRole).value<QStringList>()); | ||
break; | ||
default:; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef BUTTONDELEGATE_H | ||
#define BUTTONDELEGATE_H | ||
|
||
#include <QItemDelegate> | ||
|
||
class ButtonDelegate : public QItemDelegate | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ButtonDelegate(QObject *parent = nullptr); | ||
|
||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index); | ||
}; | ||
|
||
#endif // BUTTONDELEGATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "dmemorywarningdialog.h" | ||
#include "processinfotable.h" | ||
#include "processinfomodel.h" | ||
#include "processinfodelegate.h" | ||
#include "buttondelegate.h" | ||
|
||
#include <QKeyEvent> | ||
#include <QApplication> | ||
#include <QScreen> | ||
|
||
DMemoryWarningDialog::DMemoryWarningDialog(QWidget *parent) | ||
: QMainWindow(parent) | ||
{ | ||
ProcessInfoTable *table = new ProcessInfoTable; | ||
table->setModel(new ProcessInfoModel); | ||
table->setItemDelegate(new ProcessInfoDelegate); | ||
table->setItemDelegateForColumn(3, new ButtonDelegate); | ||
|
||
setCentralWidget(table); | ||
setFixedSize(400, 600); | ||
move(qApp->primaryScreen()->geometry().center() - rect().center()); | ||
} | ||
|
||
void DMemoryWarningDialog::keyPressEvent(QKeyEvent *e) | ||
{ | ||
switch (e->key()) | ||
{ | ||
#ifdef QT_DEBUG | ||
case Qt::Key_Escape: qApp->quit(); break; | ||
#endif | ||
default:; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef DMEMORYWARNINGDIALOG_H | ||
#define DMEMORYWARNINGDIALOG_H | ||
|
||
#include <QMainWindow> | ||
|
||
class DMemoryWarningDialog : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit DMemoryWarningDialog(QWidget *parent = nullptr); | ||
|
||
private: | ||
void keyPressEvent(QKeyEvent *e); | ||
}; | ||
|
||
#endif // DMEMORYWARNINGDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#include "dmemorywarningdialog.h" | ||
|
||
#include <DApplication> | ||
|
||
DWIDGET_USE_NAMESPACE | ||
|
||
int main(int argc, char *args[]) | ||
{ | ||
DApplication::loadDXcbPlugin(); | ||
DApplication dapp(argc, args); | ||
dapp.setAttribute(Qt::AA_UseHighDpiPixmaps); | ||
|
||
DMemoryWarningDialog dialog; | ||
dialog.show(); | ||
|
||
return dapp.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "processinfodelegate.h" | ||
#include "processinfomodel.h" | ||
|
||
#include <QApplication> | ||
#include <QDebug> | ||
#include <QPainter> | ||
|
||
ProcessInfoDelegate::ProcessInfoDelegate(QObject *parent) | ||
: QItemDelegate(parent) | ||
{ | ||
|
||
} | ||
|
||
void ProcessInfoDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
{ | ||
if (index.column() != COLUMN_ICON) | ||
return QItemDelegate::paint(painter, option, index); | ||
|
||
const QPixmap pix = index.data(ProcessInfoModel::IconRole).value<QPixmap>(); | ||
painter->drawPixmap(option.rect.center() - pix.rect().center() / pix.devicePixelRatio(), pix); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef PROCESSINFODELEGATE_H | ||
#define PROCESSINFODELEGATE_H | ||
|
||
#include <QItemDelegate> | ||
|
||
class ProcessInfoDelegate : public QItemDelegate | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ProcessInfoDelegate(QObject *parent = nullptr); | ||
|
||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||
}; | ||
|
||
#endif // PROCESSINFODELEGATE_H |
Oops, something went wrong.