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 Jan 30, 2016
1 parent baaed6a commit ac6e898
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 10 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.
10 changes: 10 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,16 @@ BBTCOView {
qproperty-textColor: rgb( 255, 255, 255 );
}

/* subwindows in MDI-Area */
SubWindow {
qproperty-activeDecorationColor: rgb(77, 96, 148);
qproperty-inactiveDecorationColor: rgb(119, 119, 119);
qproperty-leftUpperBorderColor: rgb(164,164,164);
qproperty-titelTextColor: rgb(255, 255, 255);
qproperty-windowBorderColor: rgb(0, 0, 0);
qproperty-windowDecorationBorderColor: rgb(57, 57, 57);
}

/* Plugins */

TripleOscillatorView Knob {
Expand Down
40 changes: 33 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,45 @@ class QWidget;
class EXPORT SubWindow : public QMdiSubWindow
{
Q_OBJECT
Q_PROPERTY(QColor activeDecorationColor READ activeDecorationColor WRITE setActiveDecorationColor)
Q_PROPERTY(QColor inactiveDecorationColor READ inactiveDecorationColor WRITE setInactiveDecorationColor)
Q_PROPERTY(QColor leftUpperBorderColor READ leftUpperBorderColor WRITE setLeftUpperBorderColor)
Q_PROPERTY(QColor titelTextColor READ titelTextColor WRITE setTitelTextColor)
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 activeDecorationColor() const;
QColor inactiveDecorationColor() const;
QColor leftUpperBorderColor() const;
QColor titelTextColor() const;
QColor windowBorderColor() const;
QColor windowDecorationBorderColor() const;
void setActiveDecorationColor(const QColor& c);
void setInactiveDecorationColor(const QColor &c);
void setLeftUpperBorderColor(const QColor &c);
void setTitelTextColor(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_activeDecorationColor;
QColor m_inactivDecorationColor;
QColor m_leftUpperBorderColor;
QColor m_titelTextColor;
QColor m_windowBorderColor;
QColor m_windowDecorationBorderColor;
QPoint m_position;
QRect m_trackedNormalGeom;
};

#endif
#endif
196 changes: 193 additions & 3 deletions src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
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,215 @@ 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_activeDecorationColor = QColor(77,96,148);
m_inactivDecorationColor = QColor(119,119,119);
m_leftUpperBorderColor = QColor(164,164,164);
m_titelTextColor = Qt::white;
m_windowDecorationBorderColor = QColor(57,57,57);
m_windowBorderColor = Qt::black;
}




void SubWindow::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QRectF rect(0,0,width()-1,20);
QBrush winDecoBrush;

winDecoBrush.setStyle(Qt::SolidPattern);
if ( SubWindow::mdiArea()->activeSubWindow() == this )
{
winDecoBrush.setColor(m_activeDecorationColor);
}
else
{
winDecoBrush.setColor(m_inactivDecorationColor);
}

painter.fillRect(rect,winDecoBrush);

//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(Qt::black);
painter.setPen(pen);
painter.drawText(QRect(0,0,rect.width()+1,rect.height()+1),
widget()->windowTitle(),QTextOption(Qt::AlignCenter));
pen.setColor(m_titelTextColor);
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::activeDecorationColor() const
{
return m_activeDecorationColor;
}




QColor SubWindow::inactiveDecorationColor() const
{
return m_inactivDecorationColor;
}




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




QColor SubWindow::titelTextColor() const
{
return m_titelTextColor;
}




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




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




void SubWindow::setActiveDecorationColor(const QColor &c)
{
m_activeDecorationColor = c;
}




void SubWindow::setInactiveDecorationColor(const QColor &c)
{
m_inactivDecorationColor = c;
}




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




void SubWindow::setTitelTextColor(const QColor &c)
{
m_titelTextColor = 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 ac6e898

Please sign in to comment.