Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to fix the mading error in deepin linux 15.11 ? #177

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
522 changes: 522 additions & 0 deletions CMakeLists.txt.user.38689a1

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ set(WIDGETS_FILES
./widgets/itempopupwindow.h
./widgets/switchitem.cpp
./widgets/switchitem.h
./widgets/settingsgroup.h
./widgets/settingsitem.h
./widgets/translucentframe.h
./widgets/settingsgroup.cpp
./widgets/settingsitem.cpp
./widgets/translucentframe.cpp
./widgets/switchwidget.h
./widgets/switchwidget.cpp
./widgets/labels/largelabel.h
./widgets/labels/normallabel.h
./widgets/labels/smalllabel.h
./widgets/labels/tipslabel.h
./widgets/titlevalueitem.h
./widgets/titlevalueitem.cpp
./widgets/settingsheaderitem.h
./widgets/settingsheaderitem.cpp
./widgets/settingshead.h
./widgets/settingshead.cpp
)

set(INTERFACES_FILES
Expand Down Expand Up @@ -140,12 +158,14 @@ set(NOTIFY_FILES
)

set(POWER_FILES
./modules/power/powerwidgetaction.h
./modules/power/powerplugin.cpp
./modules/power/powerplugin.h
./modules/power/powerwidget.cpp
./modules/power/powerwidget.h
./modules/power/powerwidgetaction.cpp
./modules/power/powerpopupwidget.h
./modules/power/powerpopupwidget.cpp
./modules/power/powermodel.h
./modules/power/powermodel.cpp
)

set(SEARCH_FILES
Expand Down
3 changes: 2 additions & 1 deletion src/frame/deepin-topbar.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<qresource prefix="/frame">
<file>settings.json</file>
<file>themes/dark/dark.qss</file>
</qresource>
</RCC>
61 changes: 60 additions & 1 deletion src/frame/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,63 @@

DWIDGET_USE_NAMESPACE

static const QString getQssFromFile(const QString &name)
{
#ifdef QT_DEBUG
// qDebug() << "load qss file: " << name;
#endif

QString qss;

QFile f(name);
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
qss = f.readAll();
f.close();
}

return qss;
}

static const QString getStyleSheetFromDir(QDir dir)
{
QString ret;

for (auto name : dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot)) {
if (name.suffix() == "qss") {
ret.append(getQssFromFile(name.absoluteFilePath()));
}
}

return ret;
}

static const QString styleSheetFromTheme(const QString &theme)
{
QStringList moduleList = {
"frame", "widgets",
};

QString ret;

const QString resources = ":/%1/themes/" + theme;
for (auto module : moduleList)
{
QString dir = resources.arg(module);
ret.append(getStyleSheetFromDir(dir));
}

return ret;
}

static void onThemeChange(const QString &theme)
{
QString qss;
qss.append(styleSheetFromTheme("common"));
qss.append(styleSheetFromTheme(theme));

qApp->setStyleSheet(qss);
}

int main(int argc, char *argv[])
{
if (QString(getenv("XDG_CURRENT_DESKTOP")) != QStringLiteral("Deepin")) {
Expand All @@ -15,7 +72,6 @@ int main(int argc, char *argv[])

DApplication::loadDXcbPlugin();
DApplication a(argc, argv);
a.setTheme("light");

if (a.setSingleInstance("deepin-topbar")) {
a.setApplicationName("deepin-topbar");
Expand All @@ -26,6 +82,9 @@ int main(int argc, char *argv[])
QLocale::system().name());
a.installTranslator(&translator);

a.setTheme("semidark");
onThemeChange("dark");

MainFrame *mainFrame = new MainFrame;

DBusService *dbus = new DBusService(mainFrame);
Expand Down
2 changes: 1 addition & 1 deletion src/frame/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Settings::Settings(QObject *parent)
qDebug() << "configPath" << m_configPath;
auto backend = new DTK_CORE_NAMESPACE::QSettingBackend(m_configPath);

m_settings = DTK_CORE_NAMESPACE::DSettings::fromJsonFile(":/settings.json");
m_settings = DTK_CORE_NAMESPACE::DSettings::fromJsonFile(":/frame/settings.json");
m_settings->setBackend(backend);

connect(m_settings, &DTK_CORE_NAMESPACE::DSettings::valueChanged, this, &Settings::valueChanged);
Expand Down
Empty file added src/frame/themes/dark/dark.qss
Empty file.
34 changes: 34 additions & 0 deletions src/modules/power/powermodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "powermodel.h"

using namespace dtb;
using namespace dtb::power;

PowerModel::PowerModel(QObject *parent) : QObject(parent)
{

}

void PowerModel::setShowPercentage(bool showPercentage)
{
if (m_showPercentage == showPercentage) return;

m_showPercentage = showPercentage;

emit showPercentageChanged(showPercentage);
}

void PowerModel::setBatteryStateInfo(const BatteryState &batteryStateInfo)
{
if (m_batteryStateInfo == batteryStateInfo) return;

m_batteryStateInfo = batteryStateInfo;

emit batteryStateInfoChanged(batteryStateInfo);
}

void PowerModel::setbatteryPercentage(const double batteryPercentage)
{
m_batteryPercentage = batteryPercentage;

emit batteryPercentageChanged(batteryPercentage);
}
48 changes: 48 additions & 0 deletions src/modules/power/powermodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef POWERMODEL_H
#define POWERMODEL_H

#include <QObject>

// from https://upower.freedesktop.org/docs/Device.html#Device:State
enum BatteryState
{
UNKNOWN = 0,
CHARGING = 1,
DISCHARGING = 2,
EMPTY = 3,
FULLY_CHARGED = 4,
PENDING_CHARGE = 5,
PENDING_DISCHARGE = 6
};

namespace dtb {
namespace power {
class PowerModel : public QObject
{
Q_OBJECT
public:
explicit PowerModel(QObject *parent = nullptr);

inline bool showPercentage() const { return m_showPercentage; }
inline BatteryState batteryStateInfo() const { return m_batteryStateInfo; }
inline double batteryPercentage() const { return m_batteryPercentage; }

signals:
void showPercentageChanged(bool showPercentage);
void batteryStateInfoChanged(const BatteryState& info);
void batteryPercentageChanged(const double& batteryPercentage);

public slots:
void setShowPercentage(bool showPercentage);
void setBatteryStateInfo(const BatteryState &batteryStateInfo);
void setbatteryPercentage(const double batteryPercentage);

private:
bool m_showPercentage;
BatteryState m_batteryStateInfo;
double m_batteryPercentage;
};
}
}

#endif // POWERMODEL_H
25 changes: 23 additions & 2 deletions src/modules/power/powerplugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "powerplugin.h"
#include "powerwidgetaction.h"
#include "powerpopupwidget.h"
#include "powermodel.h"

using namespace dtb;
using namespace dtb::power;
Expand All @@ -19,11 +20,26 @@ const QString PowerPlugin::pluginName() const {
void PowerPlugin::init(PluginProxyInterface *proxyInter) {
m_proxyInter = proxyInter;

m_systemPowerInter =
new SystemPowerInter("com.deepin.system.Power", "/com/deepin/system/Power",
QDBusConnection::systemBus(), this);
m_systemPowerInter->setSync(false);

m_model = new PowerModel;

connect(m_systemPowerInter, &SystemPowerInter::BatteryStatusChanged, this, &PowerPlugin::onbatteryStatusChanged);
connect(m_systemPowerInter, &SystemPowerInter::BatteryPercentageChanged, m_model, &PowerModel::setbatteryPercentage);

m_popupWidget = new PowerPopupWidget;
m_popupWidget->setModel(m_model);

m_proxyInter->addItem(this, "");

connect(m_centralWidget, &PowerWidget::requestHidePopupWindow, this, [=] {
m_proxyInter->hidePopupWindow();
});

onbatteryStatusChanged(m_systemPowerInter->batteryStatus());
}

QWidget *PowerPlugin::itemWidget(const QString &itemKey) {
Expand All @@ -36,10 +52,15 @@ QWidget *PowerPlugin::itemContextMenu(const QString &itemKey)
{
Q_UNUSED(itemKey);

return m_centralWidget->menu();
return m_popupWidget;
}

void PowerPlugin::setDefaultColor(PluginProxyInterface::DefaultColor color)
{

}

void PowerPlugin::onbatteryStatusChanged(uint state)
{
m_model->setBatteryStateInfo(static_cast<BatteryState>(state));
}
12 changes: 11 additions & 1 deletion src/modules/power/powerplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
#include "interfaces/pluginsiteminterface.h"
#include "powerwidget.h"
#include <QObject>
#include <com_deepin_system_systempower.h>

using SystemPowerInter = com::deepin::system::Power;

namespace dtb {
namespace power {

class PowerPopupWidget;
class PowerModel;
class PowerPlugin : public QObject, public PluginsItemInterface
{
Q_OBJECT
Expand All @@ -24,9 +28,15 @@ class PowerPlugin : public QObject, public PluginsItemInterface

void setDefaultColor(PluginProxyInterface::DefaultColor color) Q_DECL_OVERRIDE;

private slots:
void onbatteryStatusChanged(uint state);

private:
PluginProxyInterface *m_proxyInter;
PowerWidget *m_centralWidget;
PowerPopupWidget* m_popupWidget;
PowerModel* m_model;
SystemPowerInter *m_systemPowerInter;
};
}
}
Expand Down
43 changes: 43 additions & 0 deletions src/modules/power/powerpopupwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "powerpopupwidget.h"
#include "powermodel.h"

#include "widgets/settingsgroup.h"
#include "widgets/titlevalueitem.h"
#include "widgets/switchwidget.h"
#include "widgets/settingsheaderitem.h"

#include <QVBoxLayout>

using namespace dtb;
using namespace dtb::power;
using namespace dtb::widgets;

PowerPopupWidget::PowerPopupWidget(QWidget *parent)
: QWidget(parent)
, m_powerSettingsGrp(new SettingsGroup)
, m_sourceItem(new TitleValueItem)
, m_rcentageSwitcher(new SwitchWidget(tr("Show percentage")))
{
setFixedWidth(250);

m_sourceItem->setTitle(tr("Power Source"));
m_sourceItem->setValue(tr("Battery"));

m_powerSettingsGrp->setHeaderVisible(true);
m_powerSettingsGrp->headerItem()->setTitle(tr("Power Info"));

m_powerSettingsGrp->appendItem(m_sourceItem);
m_powerSettingsGrp->appendItem(m_rcentageSwitcher);

QVBoxLayout* layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setMargin(0);

layout->addWidget(m_powerSettingsGrp);
setLayout(layout);
}

void PowerPopupWidget::setModel(PowerModel * model)
{
m_model = model;
}
35 changes: 35 additions & 0 deletions src/modules/power/powerpopupwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef POWERPOPUPWIDGET_H
#define POWERPOPUPWIDGET_H

#include <QWidget>

namespace dtb {
namespace widgets {
class SettingsGroup;
class TitleValueItem;
class SwitchWidget;
}
namespace power {
class PowerModel;
class PowerPopupWidget : public QWidget
{
Q_OBJECT
public:
explicit PowerPopupWidget(QWidget *parent = nullptr);

void setModel(PowerModel* model);

signals:

public slots:

private:
widgets::SettingsGroup* m_powerSettingsGrp;
widgets::TitleValueItem* m_sourceItem;
widgets::SwitchWidget* m_rcentageSwitcher;
PowerModel* m_model;
};
}
}

#endif // POWERPOPUPWIDGET_H
Loading