Skip to content

Commit

Permalink
feat(TipsWidget): use one qss file
Browse files Browse the repository at this point in the history
- Using setstylesheet once will create new objects

Change-Id: I8126113766f9b1881b2b3825dc1985c6eea9b854
  • Loading branch information
haruyukilxz committed Jul 4, 2018
1 parent eb9ea57 commit 052b6b2
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 48 deletions.
2 changes: 1 addition & 1 deletion frame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
pkg_check_modules(QGSettings REQUIRED gsettings-qt)

# driver-manager
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES} item/resources.qrc)
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES} item/resources.qrc frame.qrc)
target_include_directories(${BIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
${XCB_EWMH_INCLUDE_DIRS}
${DFrameworkDBus_INCLUDE_DIRS}
Expand Down
5 changes: 5 additions & 0 deletions frame/frame.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>qss/frame.qss</file>
</qresource>
</RCC>
7 changes: 3 additions & 4 deletions frame/item/appitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ QPoint AppItem::MousePressPos;

AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
: DockItem(parent),
m_appNameTips(new QLabel(this)),
m_appNameTips(new TipsWidget(this)),
m_appPreviewTips(new PreviewContainer(this)),
m_itemEntryInter(new DockEntryInter("com.deepin.dde.daemon.Dock", entry.path(), QDBusConnection::sessionBus(), this)),

Expand Down Expand Up @@ -149,11 +149,10 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
m_id = m_itemEntryInter->id();
m_active = m_itemEntryInter->isActive();

m_appNameTips->setObjectName(m_itemEntryInter->name());
m_appNameTips->setObjectName("AppItemTips");
m_appNameTips->setAccessibleName(m_itemEntryInter->name() + "-tips");
m_appNameTips->setVisible(false);
m_appNameTips->setStyleSheet("color:white;"
"padding:0px 3px;");
m_appNameTips->installEventFilter(this);

m_updateIconGeometryTimer->setInterval(500);
m_updateIconGeometryTimer->setSingleShot(true);
Expand Down
25 changes: 13 additions & 12 deletions frame/item/appitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "dockitem.h"
#include "components/previewcontainer.h"
#include "dbus/dbusclientmanager.h"
#include "item/tipswidget.h"

#include <QGraphicsView>
#include <QGraphicsItem>
Expand Down Expand Up @@ -57,17 +58,17 @@ class AppItem : public DockItem
void requestCancelPreview() const;

private:
void moveEvent(QMoveEvent *e);
void paintEvent(QPaintEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void wheelEvent(QWheelEvent *e);
void resizeEvent(QResizeEvent *e);
void dragEnterEvent(QDragEnterEvent *e);
void dragMoveEvent(QDragMoveEvent *e);
void dropEvent(QDropEvent *e);
void leaveEvent(QEvent *e);
void moveEvent(QMoveEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void dragEnterEvent(QDragEnterEvent *e) override;
void dragMoveEvent(QDragMoveEvent *e) override;
void dropEvent(QDropEvent *e) override;
void leaveEvent(QEvent *e) override;
void showEvent(QShowEvent *e) override;

void showHoverTips();
Expand All @@ -89,7 +90,7 @@ private slots:
void checkAttentionEffect();

private:
QLabel *m_appNameTips;
TipsWidget *m_appNameTips;
PreviewContainer *m_appPreviewTips;
DockEntryInter *m_itemEntryInter;

Expand Down
2 changes: 1 addition & 1 deletion frame/item/components/appsnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent)
m_closeBtn->setHoverPic(":/icons/resources/close_round_hover.svg");
m_closeBtn->setPressPic(":/icons/resources/close_round_press.svg");
m_closeBtn->setVisible(false);
m_title->setStyleSheet("color: white;");
m_title->setObjectName("AppSnapshotTitle");

QHBoxLayout *centralLayout = new QHBoxLayout;
centralLayout->addWidget(m_title);
Expand Down
5 changes: 1 addition & 4 deletions frame/item/containeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ ContainerItem::ContainerItem(QWidget *parent)
m_containerWidget->setVisible(false);
m_popupTips->setText(tr("Click to display hidden icon"));
m_popupTips->setVisible(false);
m_popupTips->setStyleSheet("QLabel {"
"color: white;"
"margin: 2px 4px;"
"}");
m_popupTips->setObjectName("ContainerItem");

setAcceptDrops(true);
}
Expand Down
4 changes: 1 addition & 3 deletions frame/item/launcheritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ DCORE_USE_NAMESPACE
LauncherItem::LauncherItem(QWidget *parent)
: DockItem(parent),

m_tips(new QLabel(this))
m_tips(new TipsWidget(this))
{
setAccessibleName("Launcher");
m_tips->setVisible(false);
m_tips->setObjectName("launcher");
m_tips->setText(tr("Launcher"));
m_tips->setStyleSheet("color:white;"
"padding:0px 3px;");
}

void LauncherItem::refershIcon()
Expand Down
3 changes: 2 additions & 1 deletion frame/item/launcheritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define LAUNCHERITEM_H

#include "dockitem.h"
#include "tipswidget.h"

class LauncherItem : public DockItem
{
Expand All @@ -46,7 +47,7 @@ class LauncherItem : public DockItem
QPixmap m_smallIcon;
QPixmap m_largeIcon;

QLabel *m_tips;
TipsWidget *m_tips;
};

#endif // LAUNCHERITEM_H
29 changes: 29 additions & 0 deletions frame/item/tipswidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "tipswidget.h"

#include <QPainter>

TipsWidget::TipsWidget(QWidget *parent) : QFrame(parent)
{

}

void TipsWidget::setText(const QString &text)
{
m_text = text;

setFixedSize(fontMetrics().width(text) + 6, fontMetrics().height());
}

void TipsWidget::paintEvent(QPaintEvent *event)
{
QFrame::paintEvent(event);

QPainter painter(this);

QPen pen(Qt::white);
painter.setPen(pen);

QTextOption option;
option.setAlignment(Qt::AlignCenter);
painter.drawText(rect(), m_text, option);
}
21 changes: 21 additions & 0 deletions frame/item/tipswidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef TIPSWIDGET_H
#define TIPSWIDGET_H

#include <QFrame>

class TipsWidget : public QFrame
{
Q_OBJECT
public:
explicit TipsWidget(QWidget *parent = nullptr);

void setText(const QString &text);

protected:
void paintEvent(QPaintEvent *event) override;

private:
QString m_text;
};

#endif // TIPSWIDGET_H
31 changes: 9 additions & 22 deletions frame/panel/mainpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QBoxLayout>
#include <QDragEnterEvent>
#include <QApplication>

DockItem *MainPanel::DraggingItem = nullptr;
PlaceholderItem *MainPanel::RequestDockItem = nullptr;
Expand All @@ -49,28 +50,14 @@ MainPanel::MainPanel(QWidget *parent)
setAcceptDrops(true);
setAccessibleName("dock-mainpanel");
setObjectName("MainPanel");
setStyleSheet("QWidget #MainPanel {"
// "background-color:rgba(10, 10, 10, .6);"
"}"
// "QWidget #MainPanel[displayMode='1'] {"
// "border:none;"
// "}"
"QWidget #MainPanel[position='0'] {"
"padding:0 " xstr(PANEL_PADDING) "px;"
"border-top:none;"
"}"
"QWidget #MainPanel[position='1'] {"
"padding:" xstr(PANEL_PADDING) "px 0;"
"border-right:none;"
"}"
"QWidget #MainPanel[position='2'] {"
"padding:0 " xstr(PANEL_PADDING) "px;"
"border-bottom:none;"
"}"
"QWidget #MainPanel[position='3'] {"
"padding:" xstr(PANEL_PADDING) "px 0;"
"border-left:none;"
"}");

QFile qssFile(":/qss/frame.qss");

qssFile.open(QFile::ReadOnly);
if(qssFile.isOpen()) {
setStyleSheet(qssFile.readAll());
qssFile.close();
}

connect(m_itemController, &DockItemController::itemInserted, this, &MainPanel::itemInserted, Qt::DirectConnection);
connect(m_itemController, &DockItemController::itemRemoved, this, &MainPanel::itemRemoved, Qt::DirectConnection);
Expand Down
19 changes: 19 additions & 0 deletions frame/qss/frame.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#MainPanel[position='0'] {
padding: 0 0px;
border-top: none;
}

#MainPanel[position='1'] {
padding: 0px 0;
border-right: none;
}

#MainPanel[position='2'] {
padding:0 0px;
border-bottom: none;
}

#MainPanel[position='3'] {
padding: 0px 0;
border-left: none;
}

0 comments on commit 052b6b2

Please sign in to comment.