Skip to content

Commit

Permalink
Fix the segmentfault without org.ukui.style
Browse files Browse the repository at this point in the history
  • Loading branch information
handsome-feng committed Nov 27, 2020
1 parent 99770b3 commit c6d767a
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 204 deletions.
34 changes: 7 additions & 27 deletions src/cpuballwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
#include <QPainterPath>
#include <QImageReader>
#include <QGraphicsDropShadowEffect>

#include <QtMath>

qreal gradientDistance(qreal x)
{
return (1 - qCos(M_PI * x)) / 2;
}

CpuBallWidget::CpuBallWidget(QWidget *parent) : QWidget(parent)
, qtSettings(nullptr)
{
const QByteArray idd(THEME_QT_SCHEMA);

Expand Down Expand Up @@ -92,16 +93,16 @@ CpuBallWidget::~CpuBallWidget()

void CpuBallWidget::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}
//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{
if (key == "styleName")
{
// auto style = qtSettings->get(key).toString();
// qApp->setStyle(new InternalStyle(style));
currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
qDebug()<<"监听主题改变-------------------->"<<currentThemeMode<<endl;
// qApp->setStyle(new InternalStyle(currentThemeMode));
repaint();
}
});
Expand All @@ -113,34 +114,19 @@ void CpuBallWidget::loadWaveImage()
QImageReader frontReader(m_frontImagePath);
int w = frontReader.size().width();
int h = frontReader.size().height();
// w = w * this->width() / 100;
// h = h * this->height() / 100;
QImage image(w, h, QImage::Format_ARGB32_Premultiplied);//QImage::Format_ARGB32
image.fill(Qt::transparent); //Qt::transparent
image.load(m_frontImagePath);
/*QPainter painter(&image);
// painter.setCompositionMode(QPainter::CompositionMode_Source);
// painter.fillRect(image.rect(), Qt::transparent);
// painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(QPoint(0,0), image);
painter.end();*/
m_frontImage = image;

QImageReader backReader(m_backimagePath);
w = backReader.size().width();
h = backReader.size().height();
// w = w * this->width() / 100;
// h = h * this->height() / 100;

QImage backImage(w, h, QImage::Format_ARGB32_Premultiplied);//QImage::Format_ARGB32
backImage = backImage.scaled(QSize(w, h), Qt::KeepAspectRatio, Qt::SmoothTransformation);
backImage.fill(Qt::transparent);
backImage.load(m_backimagePath);
/*QPainter backPainter(&backImage);
// backPainter.setCompositionMode(QPainter::CompositionMode_Source);
// backPainter.fillRect(image.rect(), Qt::transparent);
// backPainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
backPainter.drawImage(QPoint(0,0), backImage);
backPainter.end();*/
m_backImage = backImage;
}

Expand All @@ -161,7 +147,6 @@ void CpuBallWidget::onRepaintWaveImage()
} else {
m_waveTimer->stop();
}
// this->update();//this->repaint();
}

//value:0 ~ 100
Expand Down Expand Up @@ -214,13 +199,9 @@ void CpuBallWidget::paintEvent(QPaintEvent *)
} else if (currentPercent > 55) {
m_shadowEffect->setColor(QColor(255, 193, 37));//
} else {
// m_shadowEffect->setColor(QColor(232, 232, 232, 127));//灰 the last parameters stands for the degree of the background
// m_shadowEffect->setColor(QColor(204,0,255,50));
m_shadowEffect->setColor(QColor(255,255,255,255));
// m_shadowEffect->setColor(palette().color(QPalette::Base));
}
wavePainter.fillRect(waveRectImage.rect(), QColor(255, 255, 255, 50));
// wavePainter.fillRect(waveRectImage.rect(),palette().color("QPalette::Base)");

//Step2:波浪区域
//CompositionMode_SourceOver保证波浪出现的时候其背景为通明的
Expand Down Expand Up @@ -248,7 +229,6 @@ void CpuBallWidget::paintEvent(QPaintEvent *)
QFont font = wavePainter.font();
font.setPixelSize(40);//waveSize.height() * 20 / this->height()
wavePainter.setFont(font);
// wavePainter.setPen(Qt::white);
wavePainter.setPen(QPen(palette().color(QPalette::WindowText)));
wavePainter.drawText(QRect(rect.x(), rect.y() + rect.height()*2/3, rect.width(), rect.height()/3), Qt::AlignHCenter, m_progressText);
wavePainter.end();
Expand Down
30 changes: 7 additions & 23 deletions src/cpuratewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ inline void readFile(const QString &fileName)
}

CpuRateWidget::CpuRateWidget(QWidget *parent) : QWidget(parent)
, qtSettings(nullptr)
{
const QByteArray idd(THEME_QT_SCHEMA);
if(QGSettings::isSchemaInstalled(idd))
Expand All @@ -225,39 +226,22 @@ CpuRateWidget::CpuRateWidget(QWidget *parent) : QWidget(parent)
initThemeMode();

m_cpuBall->startTimer();

/*unsigned long runtime;
unsigned long idletime;
QString rate = getIdelRate(runtime, idletime);
qDebug() << "rate="<<rate;
qDebug() << convertTimeToString(runtime);
qDebug() << convertTimeToString(idletime);*/


/*sudo dmidecode -t processor
u32 len;
u8 *buf;
size_t size = len;
buf = read_file(&size, devmem);
len = size;
// dmi_table_decode(buf, len, num, ver, flags);
// dmi_decode(&h, ver);*/
}

void CpuRateWidget::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}

//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{

if (key == "styleName")
{
// auto style = qtSettings->get(key).toString();
// qApp->setStyle(new InternalStyle(style));
currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
qDebug()<<"监听主题改变-------------------->"<<currentThemeMode<<endl;
// qApp->setStyle(new InternalStyle(currentThemeMode));
//repaint();

if(currentThemeMode == "ukui-light" || currentThemeMode == "ukui-default" || currentThemeMode =="ukui-white")
{
m_cpuRateTitle->setStyleSheet("QLabel{background:transparent;font-size:12px;color:rgba(0,0,0,0.57);}"); //#999999
Expand Down
3 changes: 3 additions & 0 deletions src/filesystemlistitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

FileSystemListItem::FileSystemListItem(FileSystemData *info)
:fontSettings(nullptr)
,qtSettings(nullptr)
{
m_data = info;
iconSize = 20;
Expand Down Expand Up @@ -69,8 +70,10 @@ FileSystemListItem::~FileSystemListItem()
void FileSystemListItem::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}

//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{
Expand Down
9 changes: 5 additions & 4 deletions src/filesystemlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FileSystemListWidget::FileSystemListWidget(QList<bool> toBeDisplayedColumns, QWi
,m_mouseAtScrollArea(false)
,m_mouseDragScrollbar(false)
,fontSettings(nullptr)
,qtSettings(nullptr)
{
const QByteArray idd(THEME_QT_SCHEMA);

Expand Down Expand Up @@ -124,17 +125,17 @@ void FileSystemListWidget::clearItems()

void FileSystemListWidget::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}
//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{

if (key == "styleName")
{
// auto style = qtSettings->get(key).toString();
// qApp->setStyle(new InternalStyle(style));
currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
qDebug()<<"监听主题改变-------------------->"<<currentThemeMode<<endl;
// qApp->setStyle(new InternalStyle(currentThemeMode));
repaint();
}
});
Expand Down
27 changes: 6 additions & 21 deletions src/monitortitlewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MonitorTitleWidget::MonitorTitleWidget(QSettings *settings, QWidget *parent)
:QFrame(parent)
,proSettings(settings)
,fontSettings(nullptr)
,qtSettings(nullptr)
{
whichBox = new QList<int>();
const QByteArray idd(THEME_QT_SCHEMA);
Expand Down Expand Up @@ -81,32 +82,12 @@ MonitorTitleWidget::MonitorTitleWidget(QSettings *settings, QWidget *parent)

initThemeMode();

this->setWindowFlags(Qt::FramelessWindowHint);//this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::WindowCloseButtonHint);
// this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);//Attention: Qt::WindowCloseButtonHint make showMinimized() valid
this->setWindowFlags(Qt::FramelessWindowHint);

installEventFilter(this);
// setMouseTracking(true);
setFixedHeight(MONITOR_TITLE_WIDGET_HEIGHT);

this->setAutoFillBackground(true);
// this->setAttribute(Qt::WA_TranslucentBackground);

// QPalette palette;
// palette.setColor(QPalette::Background, QColor("#0d87ca"));
// this->setPalette(palette);
// this->setStyleSheet("QFrame{background:transparent;background-color:#0d87ca;border-radius:5px;border:1px solid red;}");
// this->setStyleSheet("QFrame {padding: 5px 0;} QFrame:hover {background-color: rgba(255, 245, 250, 0.1);border-radius: 5px;}");

// if(currentThemeMode == "ukui-white")
// {
// this->setObjectName("MonitorTitle");
// this->setStyleSheet("QFrame#MonitorTitle{background:rgba(255,255,255,0.9);border-top-left-radius:6px;border-top-right-radius:6px;color: palette(windowText);}");
// }
// else
// {
// this->setObjectName("MonitorTitle");
// this->setStyleSheet("QFrame#MonitorTitle{background:rgba(13,14,14,0.9);border-top-left-radius:6px;border-top-right-radius:6px;color: palette(windowText);}");
// }

m_searchTimer = new QTimer(this);
m_searchTimer->setSingleShot(true);
Expand All @@ -118,6 +99,10 @@ MonitorTitleWidget::MonitorTitleWidget(QSettings *settings, QWidget *parent)

void MonitorTitleWidget::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}
//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{
Expand Down
10 changes: 6 additions & 4 deletions src/netcatogoryshow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ NetCatogoryShow::NetCatogoryShow(QWidget *parent)
,m_rectTotalHeight(38)
,m_rectTotalWidth(58)
,m_outsideBorderColor(Qt::transparent)
,qtSettings(nullptr)
{

const QByteArray idd(THEME_QT_SCHEMA);
Expand Down Expand Up @@ -66,16 +67,17 @@ NetCatogoryShow::NetCatogoryShow(QWidget *parent)

void NetCatogoryShow::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}

//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{
if (key == "styleName")
{
// auto style = qtSettings->get(key).toString();
// qApp->setStyle(new InternalStyle(style));
currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
// qDebug()<<"监听主题改变-------------------->"<<currentThemeMode<<endl;
// qApp->setStyle(new InternalStyle(currentThemeMode));
updateBgColor();
repaint();
}
Expand Down
11 changes: 6 additions & 5 deletions src/networkflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ NetworkFlow::NetworkFlow(QWidget *parent) : QWidget(parent)
,m_outsideBorderColor(QColor("transparent"))
,m_downloadColor(QColor("#009944"))
,m_uploadColor(QColor("#e60012"))
,qtSettings(nullptr)
{

const QByteArray idd(THEME_QT_SCHEMA);
Expand Down Expand Up @@ -146,20 +147,20 @@ NetworkFlow::NetworkFlow(QWidget *parent) : QWidget(parent)

void NetworkFlow::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}

//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{
if (key == "styleName")
{
// auto style = qtSettings->get(key).toString();
// qApp->setStyle(new InternalStyle(style));
currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
qDebug()<<"监听主题改变-------------------->"<<currentThemeMode<<endl;
// qApp->setStyle(new InternalStyle(currentThemeMode));

}
repaint();
// update();
});
currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
}
Expand Down
10 changes: 6 additions & 4 deletions src/networkindicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ NetworkIndicator::NetworkIndicator(QWidget *parent)
,m_rectTotalHeight(38)
,m_rectTotalWidth(58)
,m_outsideBorderColor(Qt::transparent)
,qtSettings(nullptr)
{
const QByteArray idd(THEME_QT_SCHEMA);

Expand Down Expand Up @@ -198,16 +199,17 @@ void NetworkIndicator::initWidgets()

void NetworkIndicator::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}

//监听主题改变
connect(qtSettings, &QGSettings::changed, this, [=](const QString &key)
{
if (key == "styleName")
{
// auto style = qtSettings->get(key).toString();
// qApp->setStyle(new InternalStyle(style));
currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
qDebug()<<"监听主题改变-------------------->"<<currentThemeMode<<endl;
// qApp->setStyle(new InternalStyle(currentThemeMode));
repaint();
updateBgColor();
}
Expand Down
9 changes: 5 additions & 4 deletions src/processlistitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ProcessListItem::ProcessListItem(ProcData info)
iconSize = 20;
padding = 14;
textPadding = 10;
//initThemeMode();
initThemeMode();
}

ProcessListItem::~ProcessListItem()
Expand All @@ -66,6 +66,7 @@ ProcessListItem::~ProcessListItem()
void ProcessListItem::initThemeMode()
{
if (!qtSettings) {
// qWarning() << "Failed to load the gsettings: " << THEME_QT_SCHEMA;
return;
}
//监听主题改变
Expand Down Expand Up @@ -124,11 +125,11 @@ void ProcessListItem::drawBackground(QRect rect, QPainter *painter, int index, b
if(currentThemeMode == "ukui-light" || currentThemeMode == "ukui-default" || currentThemeMode == "ukui-white")
{
painter->fillPath(path, QColor("#ffffff"));
}

if(currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black")
} else if (currentThemeMode == "ukui-dark" || currentThemeMode == "ukui-black")
{
painter->fillPath(path,QColor("#131414"));
} else {
painter->fillPath(path, QColor("000000"));
}
}
}
Expand Down
Loading

0 comments on commit c6d767a

Please sign in to comment.