mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
Use qss file to set stylesheet
This commit is contained in:
parent
8861dfbe7d
commit
eb730d09b6
29
dde-dock/Resources/qss/default.qss
Normal file
29
dde-dock/Resources/qss/default.qss
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
QLabel#Panel {
|
||||||
|
background-color: rgba(0,0,0,0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel#AppBackground[isCurrentOpened="true"][isHovered="true"] {/*item is current opened and is hovered*/
|
||||||
|
background: rgba(0,255,255,0.5);
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: rgba(255,255,255,0.3);
|
||||||
|
}
|
||||||
|
QLabel#AppBackground[isCurrentOpened="true"][isHovered="false"] {/*item is current opened but not hovered*/
|
||||||
|
background: rgba(0,255,255,0.4);
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: rgba(255,255,255,0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel#AppBackground[isActived="true"][isHovered="true"][isCurrentOpened="false"] {/*item is actived and hovered*/
|
||||||
|
background: rgba(255,255,255,0.3);
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: rgba(255,255,255,0.3);
|
||||||
|
}
|
||||||
|
QLabel#AppBackground[isActived="true"][isHovered="false"][isCurrentOpened="false"] {/*item is actived but not hovered*/
|
||||||
|
background: rgba(255,255,255,0.15);
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: rgba(255,255,255,0.3);
|
||||||
|
}
|
@ -42,7 +42,8 @@ HEADERS += \
|
|||||||
src/Widgets/appitem.h
|
src/Widgets/appitem.h
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
images.qrc
|
images.qrc \
|
||||||
|
qss.qrc
|
||||||
|
|
||||||
PKGCONFIG += gtk+-2.0 x11
|
PKGCONFIG += gtk+-2.0 x11
|
||||||
CONFIG += c++11 link_pkgconfig
|
CONFIG += c++11 link_pkgconfig
|
||||||
|
5
dde-dock/qss.qrc
Normal file
5
dde-dock/qss.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>Resources/qss/default.qss</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
@ -3,8 +3,7 @@
|
|||||||
Panel::Panel(QWidget *parent)
|
Panel::Panel(QWidget *parent)
|
||||||
: QLabel(parent),parentWidget(parent)
|
: QLabel(parent),parentWidget(parent)
|
||||||
{
|
{
|
||||||
this->setStyleSheet("QWidget{background-color: rgba(0,0,0,0.3);}");
|
this->setObjectName("Panel");
|
||||||
|
|
||||||
leftLayout = new DockLayout(this);
|
leftLayout = new DockLayout(this);
|
||||||
leftLayout->resize(1024,50);
|
leftLayout->resize(1024,50);
|
||||||
leftLayout->move(0,0);
|
leftLayout->move(0,0);
|
||||||
|
@ -3,5 +3,44 @@
|
|||||||
AppBackground::AppBackground(QWidget *parent) :
|
AppBackground::AppBackground(QWidget *parent) :
|
||||||
QLabel(parent)
|
QLabel(parent)
|
||||||
{
|
{
|
||||||
this->setStyleSheet("QLabel#AppBackground{background: rgba(255,255,255,0.3);border-radius: 4px;}");
|
this->setObjectName("AppBackground");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppBackground::getIsActived()
|
||||||
|
{
|
||||||
|
return m_isActived;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppBackground::setIsActived(bool value)
|
||||||
|
{
|
||||||
|
m_isActived = value;
|
||||||
|
|
||||||
|
style()->unpolish(this);
|
||||||
|
style()->polish(this);// force a stylesheet recomputation
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppBackground::getIsCurrentOpened()
|
||||||
|
{
|
||||||
|
return m_isCurrentOpened;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppBackground::setIsCurrentOpened(bool value)
|
||||||
|
{
|
||||||
|
m_isCurrentOpened = value;
|
||||||
|
|
||||||
|
style()->unpolish(this);
|
||||||
|
style()->polish(this);// force a stylesheet recomputation
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppBackground::getIsHovered()
|
||||||
|
{
|
||||||
|
return m_isHovered;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppBackground::setIsHovered(bool value)
|
||||||
|
{
|
||||||
|
m_isHovered = value;
|
||||||
|
|
||||||
|
style()->unpolish(this);
|
||||||
|
style()->polish(this);// force a stylesheet recomputation
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,34 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QStyle>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "dockconstants.h"
|
#include "dockconstants.h"
|
||||||
|
|
||||||
class AppBackground : public QLabel
|
class AppBackground : public QLabel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool isActived READ getIsActived WRITE setIsActived)
|
||||||
|
Q_PROPERTY(bool isCurrentOpened READ getIsCurrentOpened WRITE setIsCurrentOpened)
|
||||||
|
Q_PROPERTY(bool isHovered READ getIsHovered WRITE setIsHovered)
|
||||||
public:
|
public:
|
||||||
explicit AppBackground(QWidget *parent = 0);
|
explicit AppBackground(QWidget *parent = 0);
|
||||||
|
|
||||||
|
bool getIsActived();
|
||||||
|
void setIsActived(bool value);
|
||||||
|
bool getIsCurrentOpened();
|
||||||
|
void setIsCurrentOpened(bool value);
|
||||||
|
bool getIsHovered();
|
||||||
|
void setIsHovered(bool value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_isActived = false;
|
||||||
|
bool m_isCurrentOpened = false;
|
||||||
|
bool m_isHovered = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPBACKGROUND_H
|
#endif // APPBACKGROUND_H
|
||||||
|
@ -50,6 +50,7 @@ void AppItem::resizeResources()
|
|||||||
void AppItem::initBackground()
|
void AppItem::initBackground()
|
||||||
{
|
{
|
||||||
appBackground = new AppBackground(this);
|
appBackground = new AppBackground(this);
|
||||||
|
// appBackground->setObjectName("appBackground");
|
||||||
appBackground->resize(width(), height());
|
appBackground->resize(width(), height());
|
||||||
appBackground->move(0,0);
|
appBackground->move(0,0);
|
||||||
}
|
}
|
||||||
@ -58,6 +59,8 @@ void AppItem::mousePressEvent(QMouseEvent * event)
|
|||||||
{
|
{
|
||||||
//qWarning() << "mouse press...";
|
//qWarning() << "mouse press...";
|
||||||
emit mousePress(event->globalX(), event->globalY());
|
emit mousePress(event->globalX(), event->globalY());
|
||||||
|
////////////FOR TEST ONLY/////////////////////
|
||||||
|
appBackground->setIsActived(!appBackground->getIsActived());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppItem::mouseReleaseEvent(QMouseEvent * event)
|
void AppItem::mouseReleaseEvent(QMouseEvent * event)
|
||||||
@ -69,6 +72,8 @@ void AppItem::mouseReleaseEvent(QMouseEvent * event)
|
|||||||
void AppItem::mouseDoubleClickEvent(QMouseEvent * event)
|
void AppItem::mouseDoubleClickEvent(QMouseEvent * event)
|
||||||
{
|
{
|
||||||
emit mouseDoubleClick();
|
emit mouseDoubleClick();
|
||||||
|
////////////FOR TEST ONLY/////////////////////
|
||||||
|
appBackground->setIsCurrentOpened(!appBackground->getIsCurrentOpened());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppItem::mouseMoveEvent(QMouseEvent *event)
|
void AppItem::mouseMoveEvent(QMouseEvent *event)
|
||||||
@ -97,11 +102,13 @@ void AppItem::mouseMoveEvent(QMouseEvent *event)
|
|||||||
void AppItem::enterEvent(QEvent *event)
|
void AppItem::enterEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
emit mouseEntered();
|
emit mouseEntered();
|
||||||
|
appBackground->setIsHovered(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppItem::leaveEvent(QEvent *event)
|
void AppItem::leaveEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
emit mouseExited();
|
emit mouseExited();
|
||||||
|
appBackground->setIsHovered(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppItem::dragEnterEvent(QDragEnterEvent *event)
|
void AppItem::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDebug>
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
QFile file("://Resources/qss/default.qss");
|
||||||
|
if (file.open(QFile::ReadOnly))
|
||||||
|
{
|
||||||
|
QString styleSheet = QLatin1String(file.readAll());
|
||||||
|
qApp->setStyleSheet(styleSheet);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning() << "[Error:] Open style file errr!";
|
||||||
|
}
|
||||||
|
|
||||||
MainWidget w;
|
MainWidget w;
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user