mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 07:31:33 +08:00
Added support for CSS styling of custom widget titlebar close button
This commit is contained in:
parent
04aecb3693
commit
dcf1ee393e
@ -635,7 +635,7 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager *DockManager) :
|
||||
{
|
||||
// KDE doesn't seem to fire MoveEvents while moving windows, so for now no native titlebar for everything using KWin.
|
||||
QString window_manager = internal::windowManager().toUpper().split(" ")[0];
|
||||
bool native_window = window_manager != "KWIN";
|
||||
native_window = window_manager != "KWIN";
|
||||
}
|
||||
|
||||
if (native_window)
|
||||
|
@ -10,5 +10,9 @@
|
||||
<file>images/tabs-menu-button.svg</file>
|
||||
<file>images/detach-button.svg</file>
|
||||
<file>images/detach-button-disabled.svg</file>
|
||||
<file>images/maximize-button.svg</file>
|
||||
<file>images/maximize-button-focused.svg</file>
|
||||
<file>images/restore-button.svg</file>
|
||||
<file>images/restore-button-focused.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -60,6 +60,9 @@ struct FloatingWidgetTitleBarPrivate
|
||||
tMaximizeButton* MaximizeButton = nullptr;
|
||||
CFloatingDockContainer *FloatingWidget = nullptr;
|
||||
eDragState DragState = DraggingInactive;
|
||||
QIcon MaximizeIcon;
|
||||
QIcon NormalIcon;
|
||||
bool Maximized = false;
|
||||
|
||||
FloatingWidgetTitleBarPrivate(CFloatingWidgetTitleBar *_public) :
|
||||
_this(_public)
|
||||
@ -133,6 +136,15 @@ CFloatingWidgetTitleBar::CFloatingWidgetTitleBar(CFloatingDockContainer *parent)
|
||||
{
|
||||
d->FloatingWidget = parent;
|
||||
d->createLayout();
|
||||
|
||||
auto normalPixmap = this->style()->standardPixmap(QStyle::SP_TitleBarNormalButton, 0, d->MaximizeButton);
|
||||
d->NormalIcon.addPixmap(normalPixmap, QIcon::Normal);
|
||||
d->NormalIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
||||
|
||||
auto maxPixmap = this->style()->standardPixmap(QStyle::SP_TitleBarMaxButton, 0, d->MaximizeButton);
|
||||
d->MaximizeIcon.addPixmap(maxPixmap, QIcon::Normal);
|
||||
d->MaximizeIcon.addPixmap(internal::createTransparentPixmap(maxPixmap, 0.25), QIcon::Disabled);
|
||||
setMaximizedIcon(d->Maximized);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@ -230,22 +242,52 @@ void CFloatingWidgetTitleBar::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
//============================================================================
|
||||
void CFloatingWidgetTitleBar::setMaximizedIcon(bool maximized)
|
||||
{
|
||||
d->Maximized = maximized;
|
||||
if (maximized)
|
||||
{
|
||||
QIcon normalIcon;
|
||||
auto normalPixmap = this->style()->standardPixmap(QStyle::SP_TitleBarNormalButton, 0, d->MaximizeButton);
|
||||
normalIcon.addPixmap(normalPixmap, QIcon::Normal);
|
||||
normalIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
||||
d->MaximizeButton->setIcon(normalIcon);
|
||||
d->MaximizeButton->setIcon(d->NormalIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
QIcon MaxIcon;
|
||||
auto maxPixmap = this->style()->standardPixmap(QStyle::SP_TitleBarMaxButton, 0, d->MaximizeButton);
|
||||
MaxIcon.addPixmap(maxPixmap, QIcon::Normal);
|
||||
MaxIcon.addPixmap(internal::createTransparentPixmap(maxPixmap, 0.25), QIcon::Disabled);
|
||||
d->MaximizeButton->setIcon(MaxIcon);
|
||||
d->MaximizeButton->setIcon(d->MaximizeIcon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingWidgetTitleBar::setMaximizeIcon(const QIcon& Icon)
|
||||
{
|
||||
d->MaximizeIcon = Icon;
|
||||
if (d->Maximized)
|
||||
{
|
||||
setMaximizedIcon(d->Maximized);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingWidgetTitleBar::setNormalIcon(const QIcon& Icon)
|
||||
{
|
||||
d->NormalIcon = Icon;
|
||||
if (!d->Maximized)
|
||||
{
|
||||
setMaximizedIcon(d->Maximized);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QIcon CFloatingWidgetTitleBar::maximizeIcon() const
|
||||
{
|
||||
return d->MaximizeIcon;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QIcon CFloatingWidgetTitleBar::normalIcon() const
|
||||
{
|
||||
return d->NormalIcon;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
@ -30,6 +30,7 @@
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QFrame>
|
||||
#include <QIcon>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -48,6 +49,8 @@ struct FloatingWidgetTitleBarPrivate;
|
||||
class CFloatingWidgetTitleBar : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QIcon maximizeIcon READ maximizeIcon WRITE setMaximizeIcon)
|
||||
Q_PROPERTY(QIcon normalIcon READ normalIcon WRITE setNormalIcon)
|
||||
private:
|
||||
FloatingWidgetTitleBarPrivate *d; ///< private data (pimpl)
|
||||
|
||||
@ -57,6 +60,11 @@ protected:
|
||||
virtual void mouseMoveEvent(QMouseEvent *ev) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
void setMaximizeIcon(const QIcon& Icon);
|
||||
QIcon maximizeIcon() const;
|
||||
void setNormalIcon(const QIcon& Icon);
|
||||
QIcon normalIcon() const;
|
||||
|
||||
public:
|
||||
using Super = QWidget;
|
||||
explicit CFloatingWidgetTitleBar(CFloatingDockContainer *parent = nullptr);
|
||||
|
@ -92,13 +92,25 @@ QScrollArea#dockWidgetScrollArea {
|
||||
qproperty-iconSize: 16px;
|
||||
}
|
||||
|
||||
#floatingTitleCloseButton {
|
||||
qproperty-icon: url(:/ads/images/close-button.svg);
|
||||
|
||||
ads--CFloatingWidgetTitleBar {
|
||||
background: palette(midlight);
|
||||
qproperty-maximizeIcon: url(:/ads/images/maximize-button.svg);
|
||||
qproperty-normalIcon: url(:/ads/images/restore-button.svg);
|
||||
}
|
||||
|
||||
|
||||
#floatingTitleCloseButton, #floatingTitleMaximizeButton {
|
||||
qproperty-iconSize: 16px;
|
||||
border: none;
|
||||
margin: 3px;
|
||||
}
|
||||
|
||||
|
||||
#floatingTitleCloseButton {
|
||||
qproperty-icon: url(:/ads/images/close-button.svg);
|
||||
}
|
||||
|
||||
#floatingTitleCloseButton:hover {
|
||||
background: rgba(0, 0, 0, 24);
|
||||
border: none;
|
||||
|
@ -129,42 +129,63 @@ ads--CDockAreaWidget[focused="true"] ads--CDockAreaTitleBar {
|
||||
}
|
||||
|
||||
|
||||
ads--CFloatingWidgetTitleBar {
|
||||
background: palette(midlight);
|
||||
qproperty-maximizeIcon: url(:/ads/images/maximize-button.svg);
|
||||
qproperty-normalIcon: url(:/ads/images/restore-button.svg);
|
||||
}
|
||||
|
||||
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] ads--CFloatingWidgetTitleBar {
|
||||
background: palette(highlight);
|
||||
qproperty-maximizeIcon: url(:/ads/images/maximize-button-focused.svg);
|
||||
qproperty-normalIcon: url(:/ads/images/restore-button-focused.svg);
|
||||
}
|
||||
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleLabel {
|
||||
color: palette(light);
|
||||
color: palette(light);
|
||||
}
|
||||
|
||||
#floatingTitleCloseButton {
|
||||
qproperty-icon: url(:/ads/images/close-button.svg);
|
||||
#floatingTitleCloseButton, #floatingTitleMaximizeButton {
|
||||
qproperty-iconSize: 16px;
|
||||
border: none;
|
||||
margin: 3px;
|
||||
}
|
||||
|
||||
#floatingTitleCloseButton:hover {
|
||||
|
||||
#floatingTitleCloseButton {
|
||||
qproperty-icon: url(:/ads/images/close-button.svg);
|
||||
}
|
||||
|
||||
|
||||
#floatingTitleCloseButton:hover, #floatingTitleMaximizeButton:hover {
|
||||
background: rgba(0, 0, 0, 24);
|
||||
border: none;
|
||||
}
|
||||
|
||||
#floatingTitleCloseButton:pressed {
|
||||
|
||||
#floatingTitleCloseButton:pressed, #floatingTitleMaximizeButton:pressed {
|
||||
background: rgba(0, 0, 0, 48);
|
||||
}
|
||||
|
||||
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleMaximizeButton {
|
||||
qproperty-iconSize: 16px;
|
||||
}
|
||||
|
||||
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton {
|
||||
qproperty-icon: url(:/ads/images/close-button-focused.svg);
|
||||
qproperty-iconSize: 16px;
|
||||
}
|
||||
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton:hover {
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton:hover,
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleMaximizeButton:hover {
|
||||
background: rgba(255, 255, 255, 48);
|
||||
}
|
||||
|
||||
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton:pressed {
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton:pressed,
|
||||
ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleMaximizeButton:pressed {
|
||||
background: rgba(255, 255, 255, 92);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user