Skip to content

Commit

Permalink
Add a new window decoration to MDISubWindows
Browse files Browse the repository at this point in the history
  • Loading branch information
BaraMGB committed Feb 29, 2016
1 parent baaed6a commit 0f42b8e
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 11 deletions.
Binary file added data/themes/default/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/themes/default/maximize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/themes/default/minimize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,19 @@ BBTCOView {
qproperty-textColor: rgb( 255, 255, 255 );
}

/* subwindows in MDI-Area */
SubWindow {
qproperty-activeDecorationColor1: rgb(77, 96, 148);
qproperty-activeDecorationColor2: rgb(97, 116, 168);
qproperty-inactiveDecorationColor1: rgb(119, 119, 119);
qproperty-inactiveDecorationColor2: rgb(139, 139, 139);
qproperty-leftUpperBorderColor: rgb(164,164,164);
qproperty-titleTextColor: rgb(255, 255, 255);
qproperty-titleTextShadowColor: rgb(0, 0, 0);
qproperty-windowBorderColor: rgb(0, 0, 0);
qproperty-windowDecorationBorderColor: rgb(57, 57, 57);
}

/* Plugins */

TripleOscillatorView Knob {
Expand Down
52 changes: 45 additions & 7 deletions include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
* Boston, MA 02110-1301 USA.
*
*/


#ifndef SUBWINDOW_H
#define SUBWINDOW_H


#include <QEvent>
#include <QMdiSubWindow>
#include <QRect>

#include "export.h"

#include "PixmapButton.h"

class QMoveEvent;
class QResizeEvent;
Expand All @@ -43,16 +40,57 @@ class QWidget;
class EXPORT SubWindow : public QMdiSubWindow
{
Q_OBJECT
Q_PROPERTY(QColor activeDecorationColor1 READ activeDecorationColor1 WRITE setActiveDecorationColor1)
Q_PROPERTY(QColor activeDecorationColor2 READ activeDecorationColor2 WRITE setActiveDecorationColor2)
Q_PROPERTY(QColor inactiveDecorationColor1 READ inactiveDecorationColor1 WRITE setInactiveDecorationColor1)
Q_PROPERTY(QColor inactiveDecorationColor2 READ inactiveDecorationColor2 WRITE setInactiveDecorationColor2)
Q_PROPERTY(QColor leftUpperBorderColor READ leftUpperBorderColor WRITE setLeftUpperBorderColor)
Q_PROPERTY(QColor titleTextColor READ titleTextColor WRITE setTitleTextColor)
Q_PROPERTY(QColor titleTextShadowColor READ titleTextShadowColor WRITE setTitleTextShadowColor)
Q_PROPERTY(QColor windowBorderColor READ windowBorderColor WRITE setWindowBorderColor)
Q_PROPERTY(QColor windowDecorationBorderColor READ windowDecorationBorderColor WRITE setWindowDecorationBorderColor)

public:
SubWindow(QWidget *parent=NULL, Qt::WindowFlags windowFlags=0);
SubWindow(QWidget *parent = NULL, Qt::WindowFlags windowFlags = 0);
// same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
QRect getTrueNormalGeometry() const;
QColor activeDecorationColor1() const;
QColor activeDecorationColor2() const;
QColor inactiveDecorationColor1() const;
QColor inactiveDecorationColor2() const;
QColor leftUpperBorderColor() const;
QColor titleTextColor() const;
QColor titleTextShadowColor() const;
QColor windowBorderColor() const;
QColor windowDecorationBorderColor() const;
void setActiveDecorationColor1(const QColor& c);
void setActiveDecorationColor2(const QColor& c);
void setInactiveDecorationColor1(const QColor &c);
void setInactiveDecorationColor2(const QColor &c);
void setLeftUpperBorderColor(const QColor &c);
void setTitleTextColor(const QColor &c);
void setTitleTextShadowColor(const QColor &c);
void setWindowBorderColor(const QColor &c);
void setWindowDecorationBorderColor(const QColor &c);

protected:
// hook the QWidget move/resize events to update the tracked geometry
virtual void moveEvent(QMoveEvent * event);
virtual void resizeEvent(QResizeEvent * event);
void paintEvent(QPaintEvent *);
private:
bool m_closeHover;
QColor m_activeDecorationColor1;
QColor m_activeDecorationColor2;
QColor m_inactivDecorationColor1;
QColor m_inactivDecorationColor2;
QColor m_leftUpperBorderColor;
QColor m_titleTextColor;
QColor m_titleTextShadowColor;
QColor m_windowBorderColor;
QColor m_windowDecorationBorderColor;
QPoint m_position;
QRect m_trackedNormalGeom;
};

#endif
#endif
250 changes: 246 additions & 4 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SubWindow.cpp - Implementation of QMdiSubWindow that correctly tracks
* the geometry that windows should be restored to.
* Workaround for https://bugreports.qt.io/browse/QTBUG-256
Expand Down Expand Up @@ -26,9 +26,15 @@

#include "SubWindow.h"

#include <QIcon>
#include <QMdiArea>
#include <QMoveEvent>
#include <QPainter>
#include <QResizeEvent>
#include <QWidget>
#include "embed.h"




SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags)
Expand All @@ -37,31 +43,267 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags windowFlags)
// initialize the tracked geometry to whatever Qt thinks the normal geometry currently is.
// this should always work, since QMdiSubWindows will not start as maximized
m_trackedNormalGeom = normalGeometry();
m_activeDecorationColor1 = QColor(77,96,148);
m_activeDecorationColor2 = QColor(255,116,168);
m_inactivDecorationColor1 = QColor(119,119,119);
m_inactivDecorationColor2 = QColor(255,129,129);
m_leftUpperBorderColor = QColor(164,164,164);
m_titleTextColor = Qt::white;
m_titleTextShadowColor = Qt::black;
m_windowDecorationBorderColor = QColor(57,57,57);
m_windowBorderColor = Qt::black;
}




void SubWindow::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QRectF rect(0,0,width()-1,20);
QLinearGradient winDecoGradient(rect.topLeft() ,rect.bottomLeft() );

if ( SubWindow::mdiArea()->activeSubWindow() == this )
{
winDecoGradient.setColorAt(0,m_activeDecorationColor1);
winDecoGradient.setColorAt(1,m_activeDecorationColor2);
}
else
{
winDecoGradient.setColorAt(0,m_inactivDecorationColor1);
winDecoGradient.setColorAt(1,m_inactivDecorationColor2);
}

painter.fillRect(rect,winDecoGradient);

//window border
QPen pen;
pen.setColor(m_windowBorderColor);
painter.setPen(pen);
painter.drawRect(0,0,width()-1,height()-1);



pen.setColor(m_windowDecorationBorderColor);
painter.setPen(pen);
painter.drawRect(rect);
painter.drawLine(2,0,0,2);
painter.drawLine(width()-3,0,width()-1,2);
pen.setColor(m_leftUpperBorderColor);
painter.setPen(pen);
painter.drawLine(2,1,width()-3,1);
painter.drawLine(1,2,1,19);



//Text and Button
pen.setColor(m_titleTextShadowColor);
painter.setPen(pen);
painter.drawText(QRect(0,0,rect.width()+1,rect.height()+1),
widget()->windowTitle(),QTextOption(Qt::AlignCenter));
pen.setColor(m_titleTextColor);
painter.setPen(pen);
painter.drawText(rect, widget()->windowTitle(),QTextOption(Qt::AlignCenter));
QPixmap winicon(widget()->windowIcon().pixmap(QSize(17,17)));
QPixmap closeBtn(embed::getIconPixmap("close"));
if(windowFlags() & Qt::WindowMinimizeButtonHint)
{
int d = 0;
if (windowFlags() & Qt::WindowMaximizeButtonHint) { d = 18; }
QPixmap minimizeBtn(embed::getIconPixmap("minimize"));
painter.drawPixmap(width()-17-3-1-17-d,3,17,17,minimizeBtn);
}
if(windowFlags() & Qt::WindowMaximizeButtonHint)
{
QPixmap maximizeBtn(embed::getIconPixmap("maximize"));
painter.drawPixmap(width()-17-3-1-17,3,17,17,maximizeBtn);
}

painter.drawPixmap(3,3,17,17,winicon);
painter.drawPixmap(width()-17-3,3,17,17,closeBtn);
}




QRect SubWindow::getTrueNormalGeometry() const
{
return m_trackedNormalGeom;
}




QColor SubWindow::activeDecorationColor1() const
{
return m_activeDecorationColor1;
}




QColor SubWindow::activeDecorationColor2() const
{
return m_activeDecorationColor2;
}




QColor SubWindow::inactiveDecorationColor1() const
{
return m_inactivDecorationColor1;
}




QColor SubWindow::inactiveDecorationColor2() const
{
return m_inactivDecorationColor2;
}




QColor SubWindow::leftUpperBorderColor() const
{
return m_leftUpperBorderColor;
}




QColor SubWindow::titleTextColor() const
{
return m_titleTextColor;
}




QColor SubWindow::titleTextShadowColor() const
{
return m_titleTextShadowColor;
}




QColor SubWindow::windowBorderColor() const
{
return m_windowBorderColor;
}




QColor SubWindow::windowDecorationBorderColor() const
{
return m_windowDecorationBorderColor;
}




void SubWindow::setActiveDecorationColor1(const QColor &c)
{
m_activeDecorationColor1 = c;
}




void SubWindow::setActiveDecorationColor2(const QColor &c)
{
m_activeDecorationColor2 = c;
}




void SubWindow::setInactiveDecorationColor1(const QColor &c)
{
m_inactivDecorationColor1 = c;
}




void SubWindow::setInactiveDecorationColor2(const QColor &c)
{
m_inactivDecorationColor2 = c;
}




void SubWindow::setLeftUpperBorderColor(const QColor &c)
{
m_leftUpperBorderColor = c;
}




void SubWindow::setTitleTextColor(const QColor &c)
{
m_titleTextColor = c;
}




void SubWindow::setTitleTextShadowColor(const QColor &c)
{
m_titleTextShadowColor = c;
}




void SubWindow::setWindowBorderColor(const QColor &c)
{
m_windowBorderColor = c;
}




void SubWindow::setWindowDecorationBorderColor(const QColor &c)
{
m_windowDecorationBorderColor = c;
}




void SubWindow::moveEvent(QMoveEvent * event)
{
QMdiSubWindow::moveEvent(event);
// if the window was moved and ISN'T minimized/maximized/fullscreen,
// then save the current position
if (!isMaximized() && !isMinimized() && !isFullScreen())
if(!isMaximized() && !isMinimized() && !isFullScreen())
{
m_trackedNormalGeom.moveTopLeft(event->pos());
}
}




void SubWindow::resizeEvent(QResizeEvent * event)
{
QMdiSubWindow::resizeEvent(event);
// if the window was resized and ISN'T minimized/maximized/fullscreen,
// then save the current size
if (!isMaximized() && !isMinimized() && !isFullScreen())
if(!isMaximized() && !isMinimized() && !isFullScreen())
{
m_trackedNormalGeom.setSize(event->size());
}
}
}

//void SubWindow::mousePressEvent(QMouseEvent *event)
//{

//}

0 comments on commit 0f42b8e

Please sign in to comment.