diff --git a/clients/plastik/plastik.h b/clients/plastik/plastik.h index e9fedde510..f5e2b5f579 100644 --- a/clients/plastik/plastik.h +++ b/clients/plastik/plastik.h @@ -30,19 +30,6 @@ namespace KWinPlastik { #include -enum ButtonType { - HelpButton=0, - MaxButton, - MinButton, - CloseButton, - MenuButton, - OnAllDesktopsButton, - AboveButton, - BelowButton, - ShadeButton, - NumButtons -}; - enum ColorType { WindowContour=0, TitleGradientFrom, diff --git a/clients/plastik/plastikbutton.cpp b/clients/plastik/plastikbutton.cpp index b44eee80cc..1243393d63 100644 --- a/clients/plastik/plastikbutton.cpp +++ b/clients/plastik/plastikbutton.cpp @@ -59,31 +59,16 @@ namespace KWinPlastik static const uint TIMERINTERVAL = 50; // msec static const uint ANIMATIONSTEPS = 4; -PlastikButton::PlastikButton(PlastikClient *parent, const char *name, - const QString& tip, ButtonType type, - int size, bool toggle, int btns) - : QButton(parent->widget(), name), +PlastikButton::PlastikButton(ButtonType type, PlastikClient *parent, const char *name) + : KCommonDecorationButton(type, parent, name), m_client(parent), - m_lastMouse(NoButton), - m_realizeButtons(btns), - m_size(size), - m_type(type), m_aDecoLight(QImage() ), m_iDecoLight(QImage() ), m_aDecoDark(QImage() ), m_iDecoDark(QImage() ), hover(false) { - QToolTip::add( this, tip ); - setCursor(ArrowCursor); - setBackgroundMode(NoBackground); - setToggleButton(toggle); - - if(m_size < 10) { m_size = 10; } - - setFixedSize(m_size, m_size); - - setDeco(); + reset(); animTmr = new QTimer(this); connect(animTmr, SIGNAL(timeout() ), this, SLOT(animate() ) ); @@ -94,26 +79,7 @@ PlastikButton::~PlastikButton() { } -QSize PlastikButton::sizeHint() const -{ - return QSize(m_size, m_size); -} - -void PlastikButton::setSize(int s) -{ - m_size = s; - if(m_size < 10) { m_size = 10; } - setFixedSize(m_size, m_size); - setDeco(); -} - -void PlastikButton::setOn(bool on) -{ - QButton::setOn(on); - setDeco(); -} - -void PlastikButton::setDeco() +void PlastikButton::reset() { QColor aDecoFgDark = alphaBlendColors(PlastikHandler::getColor(TitleGradientTo, true), Qt::black, 50); @@ -136,7 +102,7 @@ void PlastikButton::setDeco() reduceH = 4; QImage img; - switch (m_type) { + switch (type() ) { case CloseButton: img = QImage(close_xpm); break; @@ -194,11 +160,6 @@ void PlastikButton::setDeco() this->update(); } -void PlastikButton::setTipText(const QString &tip) { - QToolTip::remove(this ); - QToolTip::add(this, tip ); -} - void PlastikButton::animate() { animTmr->stop(); @@ -244,31 +205,8 @@ void PlastikButton::leaveEvent(QEvent *e) // repaint(false); } -void PlastikButton::mousePressEvent(QMouseEvent* e) -{ - m_lastMouse = e->button(); - // pass on event after changing button to LeftButton - QMouseEvent me(e->type(), e->pos(), e->globalPos(), - (e->button()&m_realizeButtons)?LeftButton:NoButton, e->state()); - - QButton::mousePressEvent(&me); -} - -void PlastikButton::mouseReleaseEvent(QMouseEvent* e) -{ - m_lastMouse = e->button(); - // pass on event after changing button to LeftButton - QMouseEvent me(e->type(), e->pos(), e->globalPos(), - (e->button()&m_realizeButtons)?LeftButton:NoButton, e->state()); - - QButton::mouseReleaseEvent(&me); -} - void PlastikButton::drawButton(QPainter *painter) { - if (!PlastikHandler::initialized()) - return; - QRect r(0,0,width(),height()); bool active = m_client->isActive(); @@ -276,7 +214,7 @@ void PlastikButton::drawButton(QPainter *painter) KPixmap tempKPixmap; QColor highlightColor; - if(m_type == CloseButton) { + if(type() == CloseButton) { highlightColor = QColor(255,64,0); } else { highlightColor = Qt::white; @@ -312,7 +250,7 @@ void PlastikButton::drawButton(QPainter *painter) // fill with the titlebar background bP.drawTiledPixmap(0, 0, width(), width(), backgroundTile); - if (m_type != MenuButton || hover || animProgress != 0) { + if (type() != MenuButton || hover || animProgress != 0) { // contour bP.setPen(contourTop); bP.drawLine(r.x()+2, r.y(), r.right()-2, r.y() ); @@ -358,7 +296,7 @@ void PlastikButton::drawButton(QPainter *painter) bP.drawTiledPixmap(r.x()+1, r.y()+2, r.width()-2, r.height()-4, tempKPixmap); } - if (m_type == MenuButton) + if (type() == MenuButton) { QPixmap menuIcon(m_client->icon().pixmap( QIconSet::Small, QIconSet::Normal)); if (width() < menuIcon.width() || height() < menuIcon.height() ) { diff --git a/clients/plastik/plastikbutton.h b/clients/plastik/plastikbutton.h index 492128cae0..27e5c1b70e 100644 --- a/clients/plastik/plastikbutton.h +++ b/clients/plastik/plastikbutton.h @@ -27,27 +27,23 @@ #include #include "plastik.h" +#include + class QTimer; namespace KWinPlastik { class PlastikClient; -class PlastikButton : public QButton +class PlastikButton : public KCommonDecorationButton { Q_OBJECT public: - PlastikButton(PlastikClient *parent, const char *name, const QString &tip, ButtonType type, int size, bool toggle = false, int btns = LeftButton); + PlastikButton(ButtonType type, PlastikClient *parent, const char *name); ~PlastikButton(); - QSize sizeHint() const; ///< Return size hint. - ButtonState lastMousePress() const { return m_lastMouse; } - void reset() { repaint(false); } + void reset(); PlastikClient * client() { return m_client; } - virtual void setOn(bool on); - void setDeco(); - void setTipText(const QString &tip); - void setSize(const int s); protected slots: void animate(); @@ -55,18 +51,10 @@ protected slots: private: void enterEvent(QEvent *e); void leaveEvent(QEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); void drawButton(QPainter *painter); private: PlastikClient *m_client; - ButtonState m_lastMouse; - int m_realizeButtons; - - int m_size; - - ButtonType m_type; QImage m_aDecoLight,m_iDecoLight,m_aDecoDark,m_iDecoDark; bool hover; diff --git a/clients/plastik/plastikclient.cpp b/clients/plastik/plastikclient.cpp index e94b8f684b..e185935b36 100644 --- a/clients/plastik/plastikclient.cpp +++ b/clients/plastik/plastikclient.cpp @@ -36,34 +36,19 @@ #include #include "plastikclient.h" -#include "plastikclient.moc" #include "plastikbutton.h" #include "misc.h" #include "shadow.h" -// global constants -static const int TOPMARGIN = 4; // do not change -static const int DECOHEIGHT = 2; // do not change -static const int SIDETITLEMARGIN = 6; - -// Default button layout -const char default_left[] = "M"; -const char default_right[] = "HIAX"; - namespace KWinPlastik { PlastikClient::PlastikClient(KDecorationBridge* bridge, KDecorationFactory* factory) - : KDecoration (bridge, factory), - mainLayout_(0), - topSpacer_(0), titleSpacer_(0), leftTitleSpacer_(0), rightTitleSpacer_(0), - decoSpacer_(0), leftSpacer_(0), rightSpacer_(0), bottomSpacer_(0), + : KCommonDecoration (bridge, factory), aCaptionBuffer(0), iCaptionBuffer(0), aTitleBarTile(0), iTitleBarTile(0), aTitleBarTopTile(0), iTitleBarTopTile(0), pixmaps_created(false), captionBufferDirty(true), - closing(false), - s_titleHeight(0), s_titleFont(QFont() ) { } @@ -73,64 +58,199 @@ PlastikClient::~PlastikClient() delete aCaptionBuffer; delete iCaptionBuffer; +} - for (int n=0; nmoveResizeMaximizedWindows(); + + switch (lm) { + case LM_BorderLeft: + case LM_BorderRight: + case LM_BorderBottom: + { + if (respectWindowState && maximized) { + return 0; + } else { + return PlastikHandler::borderSize(); + } + } + + case LM_TitleEdgeTop: + { + if (respectWindowState && maximized) { + return 0; + } else { + return 4; + } + } + + case LM_TitleEdgeBottom: + { + if (respectWindowState && maximized) { + return 1; + } else { + return 2; + } + } + + case LM_TitleEdgeLeft: + case LM_TitleEdgeRight: + { + if (respectWindowState && maximized) { + return 0; + } else { + return 6; + } + } + + case LM_TitleBorderLeft: + case LM_TitleBorderRight: + return 5; + + case LM_ButtonWidth: + case LM_ButtonHeight: + case LM_TitleHeight: + { + if (respectWindowState && isToolWindow()) { + return PlastikHandler::titleHeightTool(); + } else { + return PlastikHandler::titleHeight(); + } + } + + case LM_ButtonSpacing: + return 1; + + case LM_ExplicitButtonSpacer: + return 3; + + default: + return 0; + } +} + +KCommonDecorationButton *PlastikClient::createButton(ButtonType type) +{ + switch (type) { + case MenuButton: + return new PlastikButton(MenuButton, this, "menu"); + + case OnAllDesktopsButton: + return new PlastikButton(OnAllDesktopsButton, this, "on_all_desktops"); + + case HelpButton: + return new PlastikButton(HelpButton, this, "help"); + + case MinButton: + return new PlastikButton(MinButton, this, "minimize"); + + case MaxButton: + return new PlastikButton(MaxButton, this, "maximize"); + + case CloseButton: + return new PlastikButton(CloseButton, this, "close"); + + case AboveButton: + return new PlastikButton(AboveButton, this, "above"); + + case BelowButton: + return new PlastikButton(BelowButton, this, "below"); + + case ShadeButton: + return new PlastikButton(ShadeButton, this, "shade"); + + default: + return 0; } } void PlastikClient::init() { - connect(this, SIGNAL(keepAboveChanged(bool) ), SLOT(keepAboveChange(bool) ) ); - connect(this, SIGNAL(keepBelowChanged(bool) ), SLOT(keepBelowChange(bool) ) ); - - s_titleHeight = isTool() ? - PlastikHandler::titleHeightTool() - : PlastikHandler::titleHeight(); - s_titleFont = isTool() ? + s_titleFont = isToolWindow() ? PlastikHandler::titleFontTool() - : PlastikHandler::titleFont(); - - createMainWidget(WNoAutoErase); - - widget()->installEventFilter( this ); - - // for flicker-free redraws - widget()->setBackgroundMode(NoBackground); - - _resetLayout(); + : PlastikHandler::titleFont(); create_pixmaps(); aCaptionBuffer = new QPixmap(); iCaptionBuffer = new QPixmap(); captionBufferDirty = true; - widget()->update(titleSpacer_->geometry()); + + KCommonDecoration::init(); } -const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask - | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask - | NET::UtilityMask | NET::SplashMask; - -bool PlastikClient::isTool() +QRegion PlastikClient::cornerShape(WindowCorner corner) { - NET::WindowType type = windowType( SUPPORTED_WINDOW_TYPES_MASK ); - return ((type==NET::Toolbar)||(type==NET::Utility)||(type==NET::Menu)); + int w = widget()->width(); + int h = widget()->height(); + + switch (corner) { + case WC_TopLeft: + if (layoutMetric(LM_TitleEdgeLeft) > 0) + return QRegion(0, 0, 1, 2) + QRegion(1, 0, 1, 1); + else + return QRegion(); + + case WC_TopRight: + if (layoutMetric(LM_TitleEdgeRight) > 0) + return QRegion(w-1, 0, 1, 2) + QRegion(w-2, 0, 1, 1); + else + return QRegion(); + + case WC_BottomLeft: + if (layoutMetric(LM_BorderBottom) > 0) + return QRegion(0, h-1, 1, 1); + else + return QRegion(); + + case WC_BottomRight: + if (layoutMetric(LM_BorderBottom) > 0) + return QRegion(w-1, h-1, 1, 1); + else + return QRegion(); + + default: + return QRegion(); + } + } -void PlastikClient::resizeEvent() +void PlastikClient::paintEvent(QPaintEvent *e) { - doShape(); - - // FIXME: don't update() here! this would result in two paintEvent()s - // because there is already "something" else triggering the repaint... -// widget()->update(); -} - -void PlastikClient::paintEvent(QPaintEvent*) -{ - if (!PlastikHandler::initialized()) return; + QRegion region = e->region(); + if (oldCaption != caption() ) + captionBufferDirty = true; if (captionBufferDirty) update_captionBuffer(); @@ -157,511 +277,320 @@ void PlastikClient::paintEvent(QPaintEvent*) PlastikHandler::getColor(SideHighlightBottom, active), 150); const QColor filledCorner = QColor(0,0,0); - QRect Rtop(topSpacer_->geometry()); - QRect Rtitle(titleSpacer_->geometry()); - QRect Rltitle(leftTitleSpacer_->geometry()); - QRect Rrtitle(rightTitleSpacer_->geometry()); - QRect Rdeco(decoSpacer_->geometry()); - QRect Rleft(leftSpacer_->geometry()); - QRect Rright(rightSpacer_->geometry()); - QRect Rbottom(bottomSpacer_->geometry()); + + + // often needed coordinates + QRect r = widget()->rect(); + + int r_w = r.width(); +// int r_h = r.height(); + int r_x, r_y, r_x2, r_y2; + r.coords(&r_x, &r_y, &r_x2, &r_y2); + const int borderLeft = layoutMetric(LM_BorderLeft); + const int borderRight = layoutMetric(LM_BorderRight); + const int borderBottom = layoutMetric(LM_BorderBottom); + const int titleHeight = layoutMetric(LM_TitleHeight); + const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop); + const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom); + const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft); + const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight); + + const int borderBottomTop = r_y2-borderBottom+1; + const int borderLeftRight = r_x+borderLeft-1; + const int borderRightLeft = r_x2-borderRight+1; + const int titleEdgeLeftRight = r_x+titleEdgeLeft-1; + const int titleEdgeRightLeft = r_x2-titleEdgeRight+1; + const int titleEdgeTopBottom = r_y+titleEdgeTop; + const int titleEdgeBottomTop = r_y+titleEdgeTop+titleHeight+1; + const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1; + + const int sideHeight = borderBottomTop-titleEdgeBottomBottom-1; + + QRect Rtitle = QRect(r_x+titleEdgeLeft+buttonsLeftWidth(), r_y+titleEdgeTop, + r_x2-titleEdgeRight-buttonsRightWidth()-(r_x+titleEdgeLeft+buttonsLeftWidth()), + titleEdgeBottomBottom-(r_y+titleEdgeTop) ); + QRect tempRect; // topSpacer - if(Rtop.height() > 0) + if(titleEdgeTop > 0) { painter.setPen(windowContour ); - painter.drawLine(Rtop.left()+2, Rtop.top(), Rtop.right()-2, Rtop.top() ); - painter.drawPoint(Rtop.left()+1, Rtop.top()+1 ); - painter.drawPoint(Rtop.right()-1, Rtop.top()+1 ); - painter.drawLine(Rtop.left(), Rtop.top()+2, Rtop.left(), Rtop.bottom() ); - painter.drawLine(Rtop.right(), Rtop.top()+2, Rtop.right(), Rtop.bottom() ); + painter.drawLine(r_x+2, r_y, r_x2-2, r_y ); + painter.drawPoint(r_x+1, r_y+1 ); + painter.drawPoint(r_x2-1, r_y+1 ); + painter.drawLine(r_x, r_y+2, r_x, titleEdgeTopBottom ); + painter.drawLine(r_x2, r_y+2, r_x2, titleEdgeTopBottom ); painter.setPen(highlightTop ); - painter.drawLine(Rtop.left()+3, Rtop.top()+1, Rtop.right()-3, Rtop.top()+1 ); + painter.drawLine(r_x+3, r_y+1, r_x2-3, r_y+1 ); // a bit anti-aliasing for the window contour... painter.setPen(alphaBlendColors(highlightTop, windowContour, 150) ); - painter.drawPoint(Rtop.left()+2, Rtop.top()+1); - painter.drawPoint(Rtop.right()-2, Rtop.top()+1); + painter.drawPoint(r_x+2, r_y+1); + painter.drawPoint(r_x2-2, r_y+1); painter.setPen(alphaBlendColors(highlightTitleLeft, windowContour, 150) ); - painter.drawPoint(Rtop.left()+1, Rtop.top()+2); + painter.drawPoint(r_x+1, r_y+2); painter.setPen(alphaBlendColors(highlightTitleRight, windowContour, 150) ); - painter.drawPoint(Rtop.right()-1, Rtop.top()+2); + painter.drawPoint(r_x2-1, r_y+2); // highlight... painter.setPen(highlightTitleLeft); - painter.drawLine(Rtop.left()+1, Rtop.top()+3, Rtop.left()+1, Rtop.bottom() ); + painter.drawLine(r_x+1, r_y+3, r_x+1, titleEdgeTopBottom ); painter.setPen(highlightTitleRight); - painter.drawLine(Rtop.right()-1, Rtop.top()+3, Rtop.right()-1, Rtop.bottom() ); + painter.drawLine(r_x2-1, r_y+3, r_x2-1, titleEdgeTopBottom ); - painter.drawTiledPixmap(Rtop.left()+2, Rtop.top()+2, - Rtop.width()-2*2, Rtop.height()-2, + painter.drawTiledPixmap(r_x+2, r_y+2, + r_w-2*2, titleEdgeTop-2, active ? *aTitleBarTopTile : *iTitleBarTopTile ); // outside the region normally masked by doShape painter.setPen(filledCorner); - painter.drawLine(Rtop.left(), Rtop.top(), Rtop.left()+1, Rtop.top() ); - painter.drawPoint(Rtop.left(), Rtop.top()+1); - painter.drawLine(Rtop.right(), Rtop.top(), Rtop.right()-1, Rtop.top() ); - painter.drawPoint(Rtop.right(), Rtop.top()+1); + painter.drawLine(r_x, r_y, r_x+1, r_y ); + painter.drawPoint(r_x, r_y+1); + painter.drawLine(r_x2, r_y, r_x2-1, r_y ); + painter.drawPoint(r_x2, r_y+1); } // leftTitleSpacer - if(Rltitle.width() > 0) + if(titleEdgeLeft > 0) { painter.setPen(windowContour ); - painter.drawLine(Rltitle.left(), Rltitle.top(), - Rltitle.left(), Rltitle.bottom() ); + painter.drawLine(r_x, Rtitle.top(), + r_x, Rtitle.bottom() ); painter.setPen(highlightTitleLeft); - painter.drawLine(Rltitle.left()+1, Rltitle.top(), - Rltitle.left()+1, Rltitle.bottom() ); + painter.drawLine(r_x+1, Rtitle.top(), + r_x+1, Rtitle.bottom() ); - painter.drawTiledPixmap(Rltitle.left()+2, Rltitle.top(), Rltitle.width()-2, Rltitle.height(), + painter.drawTiledPixmap(r_x+2, Rtitle.top(), titleEdgeLeft-2, Rtitle.height(), active ? *aTitleBarTile : *iTitleBarTile ); } // Space under the left button group - painter.drawTiledPixmap(Rltitle.right()+1, Rtitle.top(), - (Rtitle.left()-1)-Rltitle.right(), Rtitle.height(), + painter.drawTiledPixmap(titleEdgeLeftRight+1, Rtitle.top(), + (Rtitle.left()-1)-titleEdgeLeftRight, Rtitle.height(), active ? *aTitleBarTile : *iTitleBarTile ); // rightTitleSpacer - if(Rrtitle.width() > 0) + if(titleEdgeRight > 0) { painter.setPen(windowContour ); - painter.drawLine(Rrtitle.right(), Rrtitle.top(), - Rrtitle.right(), Rrtitle.bottom() ); + painter.drawLine(r_x2, Rtitle.top(), + r_x2, Rtitle.bottom() ); painter.setPen(highlightTitleRight); - painter.drawLine(Rrtitle.right()-1, Rrtitle.top(), - Rrtitle.right()-1, Rrtitle.bottom() ); + painter.drawLine(r_x2-1, Rtitle.top(), + r_x2-1, Rtitle.bottom() ); - painter.drawTiledPixmap(Rrtitle.left(), Rrtitle.top(), Rrtitle.width()-2, Rrtitle.height(), + painter.drawTiledPixmap(titleEdgeRightLeft, Rtitle.top(), titleEdgeRight-2, Rtitle.height(), active ? *aTitleBarTile : *iTitleBarTile ); } // Space under the right button group painter.drawTiledPixmap(Rtitle.right()+1, Rtitle.top(), - (Rrtitle.left()-1)-Rtitle.right(), Rtitle.height(), + (titleEdgeRightLeft-1)-Rtitle.right(), Rtitle.height(), active ? *aTitleBarTile : *iTitleBarTile ); // titleSpacer QPixmap *titleBfrPtr = active ? aCaptionBuffer : iCaptionBuffer; if(Rtitle.width() > 0 && titleBfrPtr != 0) { - const int titleMargin = 5; // 5 px betwee title and buttons - - int tX, tW; - switch (PlastikHandler::titleAlign()) + m_captionRect = captionRect(); // also update m_captionRect! + if (m_captionRect.isValid() && region.contains(m_captionRect) ) { - // AlignCenter - case Qt::AlignHCenter: - tX = (titleBfrPtr->width() > Rtitle.width()-2*titleMargin) ? - (Rtitle.left()+titleMargin) - : Rtitle.left()+(Rtitle.width()- titleBfrPtr->width() )/2; - tW = (titleBfrPtr->width() > Rtitle.width()-2*titleMargin) ? - (Rtitle.width()-2*titleMargin) - : titleBfrPtr->width(); - break; - // AlignRight - case Qt::AlignRight: - tX = (titleBfrPtr->width() > Rtitle.width()-2*titleMargin) ? - (Rtitle.left()+titleMargin) - : Rtitle.right()-titleMargin-titleBfrPtr->width(); - tW = (titleBfrPtr->width() > Rtitle.width()-2*titleMargin) ? - (Rtitle.width()-2*titleMargin) - : titleBfrPtr->width(); - break; - // AlignLeft - default: - tX = (Rtitle.left()+titleMargin); - tW = (titleBfrPtr->width() > Rtitle.width()-2*titleMargin) ? - (Rtitle.width()-2*titleMargin) - : titleBfrPtr->width(); + painter.drawTiledPixmap(m_captionRect, *titleBfrPtr); } - if(tW > 0) - { - painter.drawTiledPixmap(tX, Rtitle.top(), - tW, Rtitle.height(), - *titleBfrPtr); + // left to the title + tempRect.setRect(Rtitle.left(), m_captionRect.top(), + m_captionRect.left() - Rtitle.left(), m_captionRect.height() ); + if (tempRect.isValid() && region.contains(tempRect) ) { + painter.drawTiledPixmap(tempRect, active ? *aTitleBarTile : *iTitleBarTile); } - painter.drawTiledPixmap(Rtitle.left(), Rtitle.top(), - tX-Rtitle.left(), Rtitle.height(), - active ? *aTitleBarTile : *iTitleBarTile); + // right to the title + tempRect.setRect(m_captionRect.right()+1, m_captionRect.top(), + Rtitle.right() - m_captionRect.right(), m_captionRect.height() ); + if (tempRect.isValid() && region.contains(tempRect) ) { + painter.drawTiledPixmap(tempRect, active ? *aTitleBarTile : *iTitleBarTile); + } - painter.drawTiledPixmap(tX+tW, Rtitle.top(), - Rtitle.right()-(tX+tW)+1, Rtitle.height(), - active ? *aTitleBarTile : *iTitleBarTile); } titleBfrPtr = 0; // decoSpacer - if(Rdeco.height() > 0) + if(titleEdgeBottom > 0) { int l; - if(Rleft.width() != 0) - l = Rdeco.left()+2; + if(borderLeft != 0) + l = r_x+2; else - l = Rdeco.left(); + l = r_x; int r; - if(Rright.width() != 0) - r = Rdeco.right()-2; + if(borderRight != 0) + r = r_x2-2; else - r = Rdeco.right(); + r = r_x2; painter.setPen(deco ); - painter.drawLine(l, Rdeco.bottom(), r, Rdeco.bottom() ); - painter.drawLine(l, Rdeco.top(), r, Rdeco.top() ); - if(Rleft.width() != 0) { + painter.drawLine(l, titleEdgeBottomBottom-1, r, titleEdgeBottomBottom-1 ); + painter.drawLine(l, titleEdgeBottomBottom, r, titleEdgeBottomBottom ); + if(borderLeft != 0) { painter.setPen(windowContour ); - painter.drawLine(Rdeco.left(), Rdeco.top(), Rdeco.left(), Rdeco.bottom() ); + painter.drawLine(r_x, titleEdgeBottomTop, r_x, titleEdgeBottomBottom ); painter.setPen(highlightTitleLeft); - painter.drawLine(Rdeco.left()+1, Rdeco.top(), - Rdeco.left()+1, Rdeco.bottom() ); + painter.drawLine(r_x+1, titleEdgeBottomTop, + r_x+1, titleEdgeBottomBottom ); } - if(Rright.width() != 0) { + if(borderRight != 0) { painter.setPen(windowContour ); - painter.drawLine(Rdeco.right(), Rdeco.top(), Rdeco.right(), Rdeco.bottom() ); + painter.drawLine(r_x2, titleEdgeBottomTop, r_x2, titleEdgeBottomBottom ); painter.setPen(highlightTitleRight); - painter.drawLine(Rdeco.right()-1, Rdeco.top(), - Rdeco.right()-1, Rdeco.bottom() ); + painter.drawLine(r_x2-1, titleEdgeBottomTop, + r_x2-1, titleEdgeBottomBottom ); } } // leftSpacer - if(Rleft.width() > 0 && Rleft.height() > 0) + if(borderLeft > 0 && sideHeight > 0) { painter.setPen(windowContour ); - painter.drawLine(Rleft.left(), Rleft.top(), - Rleft.left(), Rleft.bottom() ); + painter.drawLine(r_x, titleEdgeBottomBottom+1, + r_x, borderBottomTop-1 ); painter.setPen(highlightLeft ); - painter.drawLine(Rleft.left()+1, Rleft.top(), - Rleft.left()+1, Rleft.bottom() ); - if(Rleft.width() > 2) { - tempRect.setCoords(Rleft.left()+2, Rleft.top(), - Rleft.right(), Rleft.bottom() ); + painter.drawLine(r_x+1, titleEdgeBottomBottom+1, + r_x+1, borderBottomTop-1 ); + if(borderLeft > 2) { + tempRect.setCoords(r_x+2, titleEdgeBottomBottom+1, + borderLeftRight, borderBottomTop-1 ); painter.fillRect(tempRect, border ); } } // rightSpacer - if(Rright.width() > 0 && Rright.height() > 0) + if(borderRight > 0 && sideHeight > 0) { painter.setPen(windowContour ); - painter.drawLine(Rright.right(), Rright.top(), - Rright.right(), Rright.bottom() ); + painter.drawLine(r_x2, titleEdgeBottomBottom+1, + r_x2, borderBottomTop-1 ); painter.setPen(highlightRight ); - painter.drawLine(Rright.right()-1, Rright.top(), - Rright.right()-1, Rright.bottom() ); - if(Rright.width() > 2) { - tempRect.setCoords(Rright.left(), Rright.top(), - Rright.right()-2, Rright.bottom() ); + painter.drawLine(r_x2-1, titleEdgeBottomBottom+1, + r_x2-1, borderBottomTop-1 ); + if(borderRight > 2) { + tempRect.setCoords(borderRightLeft, titleEdgeBottomBottom+1, + r_x2-2, borderBottomTop-1 ); painter.fillRect(tempRect, border ); } } // bottomSpacer - if(Rbottom.height() > 0) + if(borderBottom > 0) { painter.setPen(windowContour ); - painter.drawLine(Rbottom.left()+1, Rbottom.bottom(), - Rbottom.right()-1, Rbottom.bottom() ); + painter.drawLine(r_x+1, r_y2, + r_x2-1, r_y2 ); - if(Rleft.width() != 0) { + if(borderLeft != 0) { painter.setPen(windowContour ); - painter.drawLine(Rbottom.left(), Rbottom.top(), - Rbottom.left(), Rbottom.bottom()-1 ); + painter.drawLine(r_x, borderBottomTop, + r_x, r_y2-1 ); painter.setPen(highlightLeft ); - painter.drawLine(Rbottom.left()+1, Rbottom.top(), - Rbottom.left()+1, Rbottom.bottom()-2 ); + painter.drawLine(r_x+1, borderBottomTop, + r_x+1, r_y2-2 ); // anti-alias for the window contour... painter.setPen(alphaBlendColors(border, windowContour, 110) ); - painter.drawPoint(Rbottom.left()+1, Rbottom.bottom()-1); + painter.drawPoint(r_x+1, r_y2-1); } - if(Rright.width() != 0) { + if(borderRight != 0) { painter.setPen(windowContour ); - painter.drawLine(Rbottom.right(), Rbottom.top(), - Rbottom.right(), Rbottom.bottom()-1 ); + painter.drawLine(r_x2, borderBottomTop, + r_x2, r_y2-1 ); painter.setPen(highlightRight ); - painter.drawLine(Rbottom.right()-1, Rbottom.top(), - Rbottom.right()-1, Rbottom.bottom()-2 ); + painter.drawLine(r_x2-1, borderBottomTop, + r_x2-1, r_y2-2 ); // anti-alias for the window contour... painter.setPen(alphaBlendColors(border, windowContour, 110) ); - painter.drawPoint(Rbottom.right()-1, Rbottom.bottom()-1); + painter.drawPoint(r_x2-1, r_y2-1); } // outside the region normally masked by doShape painter.setPen(filledCorner); - painter.drawPoint(Rbottom.left(), Rbottom.bottom()); - painter.drawPoint(Rbottom.right(), Rbottom.bottom()); + painter.drawPoint(r_x, r_y2); + painter.drawPoint(r_x2, r_y2); int l; - if(Rleft.width() != 0) - l = Rbottom.left()+2; + if(borderLeft != 0) + l = r_x+2; else - l = Rbottom.left(); + l = r_x; int r; - if(Rright.width() != 0) - r = Rbottom.right()-2; + if(borderRight != 0) + r = r_x2-2; else - r = Rbottom.right(); + r = r_x2; painter.setPen(highlightBottom ); - painter.drawLine(l, Rbottom.bottom()-1, - r, Rbottom.bottom()-1 ); + painter.drawLine(l, r_y2-1, + r, r_y2-1 ); - tempRect.setCoords(l, Rbottom.top(), r, Rbottom.bottom()-2); + tempRect.setCoords(l, borderBottomTop, r, r_y2-2); painter.fillRect(tempRect, border ); } } -void PlastikClient::mouseDoubleClickEvent(QMouseEvent *e) +QRect PlastikClient::captionRect() const { - if (titleSpacer_->geometry().contains(e->pos())) - titlebarDblClickOperation(); -} + QPixmap *titleBfrPtr = isActive() ? aCaptionBuffer : iCaptionBuffer; + if (titleBfrPtr) { + QRect r = widget()->rect(); -void PlastikClient::doShape() -{ - int w = widget()->width(); - int h = widget()->height(); - int r(w); - int b(h); - bool tl=true,tr=true,bl=true,br=true; // is there a transparent rounded corner in top-left? etc - - QRegion mask(0, 0, w, h); - - QDesktopWidget *desktop=KApplication::desktop(); + const int titleHeight = layoutMetric(LM_TitleHeight); + const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop); + const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft); + const int marginLeft = layoutMetric(LM_TitleBorderLeft); + const int marginRight = layoutMetric(LM_TitleBorderRight); - // no transparent rounded corners if the spacers are zero size - if(topSpacer_->geometry().height() == 0) tl = tr = false; - if(leftTitleSpacer_->geometry().width() == 0) tl = false; - if(rightTitleSpacer_->geometry().width() == 0) tr = false; - if(bottomSpacer_->geometry().height() == 0) bl = br = false; - - // no transparent rounded corners if this window corner lines up with a screen corner - for(int screen=desktop->numScreens()-1;screen>=0;--screen) - { - QRect fullscreen(desktop->screenGeometry(screen)); - QRect wcfullscreen(widget()->mapFromGlobal(fullscreen.topLeft()), - widget()->mapFromGlobal(fullscreen.bottomRight()+QPoint(1,1))); - - if(wcfullscreen.topLeft() ==QPoint(0,0)) tl = false; - if(wcfullscreen.topRight() ==QPoint(w,0)) tr = false; - if(wcfullscreen.bottomLeft() ==QPoint(0,h)) bl = false; - if(wcfullscreen.bottomRight()==QPoint(w,h)) br = false; - } + const int titleLeft = r.left() + titleEdgeLeft + buttonsLeftWidth() + marginLeft; + const int titleWidth = r.width() - + titleEdgeLeft - layoutMetric(LM_TitleEdgeRight) - + buttonsLeftWidth() - buttonsRightWidth() - + marginLeft - marginRight; - if(tl) // remove top-left corner - { - mask -= QRegion(0, 0, 1, 2); - mask -= QRegion(1, 0, 1, 1); - } - - if(tr) // remove top-right corner - { - mask -= QRegion(r-1, 0, 1, 2); - mask -= QRegion(r-2, 0, 1, 1); - } - - if(bl) // remove bottom-left corner - { - mask -= QRegion(0, b-1, 1, 1); - } - - if(br) // remove bottom-right corner - { - mask -= QRegion(r-1, b-1, 1, 1); - } + Qt::AlignmentFlags a = PlastikHandler::titleAlign(); - setMask( mask ); -} - -void PlastikClient::_resetLayout() -{ - // basic layout: - // _______________________________________________________________ - // | topSpacer | - // |_______________________________________________________________| - // | leftTitleSpacer | btns | titleSpacer | bts | rightTitleSpacer | - // |_________________|______|_____________|_____|__________________| - // | decoSpacer | - // |_______________________________________________________________| - // | | | | - // | | contentsFake | | - // | | | | - // |leftSpacer rightSpacer| - // |_|___________________________________________________________|_| - // | bottomSpacer | - // |_______________________________________________________________| - // - - if (!PlastikHandler::initialized()) return; - - delete mainLayout_; - - delete topSpacer_; - delete titleSpacer_; - delete leftTitleSpacer_; - delete rightTitleSpacer_; - delete decoSpacer_; - delete leftSpacer_; - delete rightSpacer_; - delete bottomSpacer_; - - mainLayout_ = new QVBoxLayout(widget(), 0, 0); - - topSpacer_ = new QSpacerItem(1, TOPMARGIN, QSizePolicy::Expanding, QSizePolicy::Fixed); - titleSpacer_ = new QSpacerItem(1, s_titleHeight, - QSizePolicy::Expanding, QSizePolicy::Fixed); - leftTitleSpacer_ = new QSpacerItem(SIDETITLEMARGIN, s_titleHeight, - QSizePolicy::Fixed, QSizePolicy::Fixed); - rightTitleSpacer_ = new QSpacerItem(SIDETITLEMARGIN, s_titleHeight, - QSizePolicy::Fixed, QSizePolicy::Fixed); - decoSpacer_ = new QSpacerItem(1, DECOHEIGHT, QSizePolicy::Expanding, QSizePolicy::Fixed); - leftSpacer_ = new QSpacerItem(PlastikHandler::borderSize(), 1, - QSizePolicy::Fixed, QSizePolicy::Expanding); - rightSpacer_ = new QSpacerItem(PlastikHandler::borderSize(), 1, - QSizePolicy::Fixed, QSizePolicy::Expanding); - bottomSpacer_ = new QSpacerItem(1, PlastikHandler::borderSize(), - QSizePolicy::Expanding, QSizePolicy::Fixed); - - // top - mainLayout_->addItem(topSpacer_); - - // title - QHBoxLayout *titleLayout_ = new QHBoxLayout(mainLayout_, 0, 0); - - // sizeof(...) is calculated at compile time - memset(m_button, 0, sizeof(PlastikButton *) * NumButtons); - - titleLayout_->addItem(PlastikHandler::reverseLayout()?rightTitleSpacer_:leftTitleSpacer_); - addButtons(titleLayout_, - options()->customButtonPositions() ? options()->titleButtonsLeft() : QString(default_left), - s_titleHeight-1); - titleLayout_->addItem(titleSpacer_); - addButtons(titleLayout_, - options()->customButtonPositions() ? options()->titleButtonsRight() : QString(default_right), - s_titleHeight-1); - titleLayout_->addItem(PlastikHandler::reverseLayout()?leftTitleSpacer_:rightTitleSpacer_); - - // deco - mainLayout_->addItem(decoSpacer_); - - //Mid - QHBoxLayout * midLayout = new QHBoxLayout(mainLayout_, 0, 0); - midLayout->addItem(PlastikHandler::reverseLayout()?rightSpacer_:leftSpacer_); - if( isPreview()) - midLayout->addWidget(new QLabel( i18n( "
Plastik preview
" ), widget()) ); - else - midLayout->addItem( new QSpacerItem( 0, 0 )); - midLayout->addItem(PlastikHandler::reverseLayout()?leftSpacer_:rightSpacer_); - - //Bottom - mainLayout_->addItem(bottomSpacer_); - - -} - -void PlastikClient::addButtons(QBoxLayout *layout, const QString& s, int buttonSize) -{ - if (s.length() > 0) { - for (unsigned n=0; n < s.length(); n++) { - switch (s[n]) { - case 'M': // Menu button - if (!m_button[MenuButton]){ - m_button[MenuButton] = new PlastikButton(this, "menu", i18n("Menu"), MenuButton, buttonSize, LeftButton|RightButton); - connect(m_button[MenuButton], SIGNAL(pressed()), SLOT(menuButtonPressed())); - connect(m_button[MenuButton], SIGNAL(released()), this, SLOT(menuButtonReleased())); - layout->addWidget(m_button[MenuButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'S': // OnAllDesktops button - if (!m_button[OnAllDesktopsButton]){ - const bool oad = isOnAllDesktops(); - m_button[OnAllDesktopsButton] = new PlastikButton(this, "on_all_desktops", - oad?i18n("Not on all desktops"):i18n("On all desktops"), OnAllDesktopsButton, - buttonSize, true); - m_button[OnAllDesktopsButton]->setOn( oad ); - connect(m_button[OnAllDesktopsButton], SIGNAL(clicked()), SLOT(toggleOnAllDesktops())); - layout->addWidget(m_button[OnAllDesktopsButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'H': // Help button - if ((!m_button[HelpButton]) && providesContextHelp()){ - m_button[HelpButton] = new PlastikButton(this, "help", i18n("Help"), HelpButton, buttonSize); - connect(m_button[HelpButton], SIGNAL(clicked()), SLOT(showContextHelp())); - layout->addWidget(m_button[HelpButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'I': // Minimize button - if ((!m_button[MinButton]) && isMinimizable()){ - m_button[MinButton] = new PlastikButton(this, "minimize", i18n("Minimize"), MinButton, buttonSize); - connect(m_button[MinButton], SIGNAL(clicked()), SLOT(minimize())); - layout->addWidget(m_button[MinButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'A': // Maximize button - if ((!m_button[MaxButton]) && isMaximizable()){ - const bool max = maximizeMode()!=MaximizeRestore; - m_button[MaxButton] = new PlastikButton(this, "maximize", - max?i18n("Restore"):i18n("Maximize"), MaxButton, buttonSize, - true, LeftButton|MidButton|RightButton); - m_button[MaxButton]->setOn( max ); - connect(m_button[MaxButton], SIGNAL(clicked()), SLOT(slotMaximize())); - layout->addWidget(m_button[MaxButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'X': // Close button - if ((!m_button[CloseButton]) && isCloseable()){ - m_button[CloseButton] = new PlastikButton(this, "close", i18n("Close"), CloseButton, buttonSize); - connect(m_button[CloseButton], SIGNAL(clicked()), SLOT(closeWindow())); - layout->addWidget(m_button[CloseButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'F': // AboveButton button - if (!m_button[AboveButton]){ - bool above = keepAbove(); - m_button[AboveButton] = new PlastikButton(this, "above", - above?i18n("Do not keep above others"):i18n("Keep above others"), AboveButton, buttonSize, true); - m_button[AboveButton]->setOn( above ); - connect(m_button[AboveButton], SIGNAL(clicked()), SLOT(slotKeepAbove())); - layout->addWidget(m_button[AboveButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'B': // BelowButton button - if (!m_button[BelowButton]){ - bool below = keepBelow(); - m_button[BelowButton] = new PlastikButton(this, "below", - below?i18n("Do not keep below others"):i18n("Keep below others"), BelowButton, buttonSize, true); - m_button[BelowButton]->setOn( below ); - connect(m_button[BelowButton], SIGNAL(clicked()), SLOT(slotKeepBelow())); - layout->addWidget(m_button[BelowButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case 'L': // Shade button - if ((!m_button[ShadeButton]) && isShadeable()){ - bool shaded = isSetShade(); - m_button[ShadeButton] = new PlastikButton(this, "shade", - shaded?i18n("Unshade"):i18n("Shade"), ShadeButton, buttonSize, true); - m_button[ShadeButton]->setOn( shaded ); - connect(m_button[ShadeButton], SIGNAL(clicked()), SLOT(slotShade())); - layout->addWidget(m_button[ShadeButton], 0, Qt::AlignHCenter | Qt::AlignTop); - } - break; - case '_': // Spacer item - layout->addSpacing(3); // add a 3 px spacing... - } - - // add 2 px spacing between buttons - if(n < (s.length()-1) ) // and only between them! - layout->addSpacing (1); + int tX, tW; // position/width of the title buffer + if (titleBfrPtr->width() > titleWidth) { + tW = titleWidth; + } else { + tW = titleBfrPtr->width(); } + if (a == Qt::AlignLeft || (titleBfrPtr->width() > titleWidth) ) { + // Align left + tX = titleLeft; + } else if (a == Qt::AlignHCenter) { + // Align center + tX = titleLeft+(titleWidth- titleBfrPtr->width() )/2; + } else { + // Align right + tX = titleLeft+titleWidth-titleBfrPtr->width(); + } + + return QRect(tX, r.top()+titleEdgeTop, tW, titleHeight); } + + return QRect(); } -void PlastikClient::captionChange() +void PlastikClient::updateCaption() { - captionBufferDirty = true; - widget()->update(titleSpacer_->geometry()); + QRect oldCaptionRect = m_captionRect; + + if (oldCaption != caption() ) + captionBufferDirty = true; + if (captionBufferDirty) + update_captionBuffer(); + + m_captionRect = PlastikClient::captionRect(); + + if (oldCaptionRect.isValid() && m_captionRect.isValid() ) + widget()->update(oldCaptionRect|m_captionRect); + else + widget()->update(); } void PlastikClient::reset( unsigned long changed ) @@ -673,217 +602,23 @@ void PlastikClient::reset( unsigned long changed ) create_pixmaps(); captionBufferDirty = true; widget()->update(); - for (int n=0; nupdate(); - } + updateButtons(); } else if (changed & SettingFont) { // font has changed -- update title height and font - s_titleHeight = isTool() ? - PlastikHandler::titleHeightTool() - : PlastikHandler::titleHeight(); - s_titleFont = isTool() ? + s_titleFont = isToolWindow() ? PlastikHandler::titleFontTool() : PlastikHandler::titleFont(); - // update buttons - for (int n=0; nsetSize(s_titleHeight-1); - } - // update the spacer - titleSpacer_->changeSize(1, s_titleHeight, - QSizePolicy::Expanding, QSizePolicy::Fixed); + + updateLayout(); + // then repaint delete_pixmaps(); create_pixmaps(); captionBufferDirty = true; widget()->update(); } -} -PlastikClient::Position PlastikClient::mousePosition(const QPoint &point) const -{ - const int corner = 18+3*PlastikHandler::borderSize()/2; - Position pos = PositionCenter; - - // often needed coords.. - QRect topRect(topSpacer_->geometry()); - QRect decoRect(decoSpacer_->geometry()); - QRect leftRect(leftSpacer_->geometry()); - QRect leftTitleRect(leftTitleSpacer_->geometry()); - QRect rightRect(rightSpacer_->geometry()); - QRect rightTitleRect(rightTitleSpacer_->geometry()); - QRect bottomRect(bottomSpacer_->geometry()); - - if(bottomRect.contains(point)) { - if (point.x() <= bottomRect.left()+corner) pos = PositionBottomLeft; - else if (point.x() >= bottomRect.right()-corner) pos = PositionBottomRight; - else pos = PositionBottom; - } - else if(leftRect.contains(point)) { - if (point.y() <= topRect.top()+corner) pos = PositionTopLeft; - else if (point.y() >= bottomRect.bottom()-corner) pos = PositionBottomLeft; - else pos = PositionLeft; - } - else if(leftTitleRect.contains(point)) { - if (point.y() <= topRect.top()+corner) pos = PositionTopLeft; - else pos = PositionLeft; - } - else if(rightRect.contains(point)) { - if (point.y() <= topRect.top()+corner) pos = PositionTopRight; - else if (point.y() >= bottomRect.bottom()-corner) pos = PositionBottomRight; - else pos = PositionRight; - } - else if(rightTitleRect.contains(point)) { - if (point.y() <= topRect.top()+corner) pos = PositionTopRight; - else pos = PositionRight; - } - else if(topRect.contains(point)) { - if (point.x() <= topRect.left()+corner) pos = PositionTopLeft; - else if (point.x() >= topRect.right()-corner) pos = PositionTopRight; - else pos = PositionTop; - } - else if(decoRect.contains(point)) { - if(point.x() <= leftTitleRect.right()) { - if(point.y() <= topRect.top()+corner) pos = PositionTopLeft; - else pos = PositionLeft; - } - else if(point.x() >= rightTitleRect.left()) { - if(point.y() <= topRect.top()+corner) pos = PositionTopRight; - else pos = PositionRight; - } - } - - return pos; -} - -void PlastikClient::iconChange() -{ - if (m_button[MenuButton]) - { - m_button[MenuButton]->update(); - } -} - -void PlastikClient::activeChange() -{ - for (int n=0; nupdate(); - widget()->update(); -} - -void PlastikClient::maximizeChange() -{ - if (!PlastikHandler::initialized()) return; - - if( m_button[MaxButton] ) { - m_button[MaxButton]->setOn( maximizeMode()==MaximizeFull); - m_button[MaxButton]->setTipText( (maximizeMode()!=MaximizeFull) ? - i18n("Maximize") - : i18n("Restore")); - } -} - -void PlastikClient::desktopChange() -{ - if ( m_button[OnAllDesktopsButton] ) { - m_button[OnAllDesktopsButton]->setOn( isOnAllDesktops() ); - m_button[OnAllDesktopsButton]->setTipText( isOnAllDesktops() ? - i18n("Not on all desktops") - : i18n("On all desktops")); - } -} - -void PlastikClient::shadeChange() -{ - if ( m_button[ShadeButton] ) { - bool shaded = isSetShade(); - m_button[ShadeButton]->setOn( shaded ); - m_button[ShadeButton]->setTipText( shaded ? - i18n("Unshade") - : i18n("Shade")); - } -} - -void PlastikClient::slotMaximize() -{ - if (m_button[MaxButton]) - { - maximize(m_button[MaxButton]->lastMousePress() ); - doShape(); - } -} - -void PlastikClient::slotShade() -{ - setShade( !isSetShade() ); -} - -void PlastikClient::slotKeepAbove() -{ - setKeepAbove(!keepAbove() ); -} - -void PlastikClient::slotKeepBelow() -{ - setKeepBelow(!keepBelow() ); -} - -void PlastikClient::keepAboveChange(bool above) -{ - if (m_button[AboveButton]) - { - m_button[AboveButton]->setOn(above); - m_button[AboveButton]->setTipText( above?i18n("Do not keep above others"):i18n("Keep above others") ); - } - - if (m_button[BelowButton] && m_button[BelowButton]->isOn()) - { - m_button[BelowButton]->setOn(false); - m_button[BelowButton]->setTipText( i18n("Keep below others") ); - } -} - -void PlastikClient::keepBelowChange(bool below) -{ - if (m_button[BelowButton]) - { - m_button[BelowButton]->setOn(below); - m_button[BelowButton]->setTipText( below?i18n("Do not keep below others"):i18n("Keep below others") ); - } - - if (m_button[AboveButton] && m_button[AboveButton]->isOn()) - { - m_button[AboveButton]->setOn(false); - m_button[AboveButton]->setTipText( i18n("Keep above others") ); - } -} - -void PlastikClient::menuButtonPressed() -{ - static QTime* t = NULL; - static PlastikClient* lastClient = NULL; - if (t == NULL) - t = new QTime; - bool dbl = (lastClient==this && t->elapsed() <= QApplication::doubleClickInterval()); - lastClient = this; - t->start(); - if (!dbl || !PlastikHandler::menuClose()) { - QRect menuRect = m_button[MenuButton]->rect(); - QPoint menutop = m_button[MenuButton]->mapToGlobal(menuRect.topLeft()); - QPoint menubottom = m_button[MenuButton]->mapToGlobal(menuRect.bottomRight()); - KDecorationFactory* f = factory(); - showWindowMenu(QRect(menutop, menubottom)); - if( !f->exists( this )) // 'this' was deleted - return; - m_button[MenuButton]->setDown(false); - } - else - closing = true; -} - -void PlastikClient::menuButtonReleased() -{ - if(closing) - closeWindow(); + KCommonDecoration::reset(changed); } void PlastikClient::create_pixmaps() @@ -894,46 +629,49 @@ void PlastikClient::create_pixmaps() KPixmap tempPixmap; QPainter painter; + const int tet = layoutMetric(LM_TitleEdgeTop, false); + const int th = layoutMetric(LM_TitleHeight, false); + // aTitleBarTopTile - tempPixmap.resize(1, TOPMARGIN-1-1 ); + tempPixmap.resize(1, tet-1-1 ); KPixmapEffect::gradient(tempPixmap, PlastikHandler::getColor(TitleGradientToTop, true), PlastikHandler::getColor(TitleGradientFrom, true), KPixmapEffect::VerticalGradient); - aTitleBarTopTile = new QPixmap(1, TOPMARGIN-1-1 ); + aTitleBarTopTile = new QPixmap(1, tet-1-1 ); painter.begin(aTitleBarTopTile); painter.drawPixmap(0, 0, tempPixmap); painter.end(); // aTitleBarTile - tempPixmap.resize(1, s_titleHeight ); + tempPixmap.resize(1, th ); KPixmapEffect::gradient(tempPixmap, PlastikHandler::getColor(TitleGradientFrom, true), PlastikHandler::getColor(TitleGradientTo, true), KPixmapEffect::VerticalGradient); - aTitleBarTile = new QPixmap(1, s_titleHeight ); + aTitleBarTile = new QPixmap(1, th ); painter.begin(aTitleBarTile); painter.drawPixmap(0, 0, tempPixmap); painter.end(); // iTitleBarTopTile - tempPixmap.resize(1, TOPMARGIN-1-1 ); + tempPixmap.resize(1, tet-1-1 ); KPixmapEffect::gradient(tempPixmap, PlastikHandler::getColor(TitleGradientToTop, false), PlastikHandler::getColor(TitleGradientFrom, false), KPixmapEffect::VerticalGradient); - iTitleBarTopTile = new QPixmap(1, TOPMARGIN-1-1 ); + iTitleBarTopTile = new QPixmap(1, tet-1-1 ); painter.begin(iTitleBarTopTile); painter.drawPixmap(0, 0, tempPixmap); painter.end(); // iTitleBarTile - tempPixmap.resize(1, s_titleHeight ); + tempPixmap.resize(1, th ); KPixmapEffect::gradient(tempPixmap, PlastikHandler::getColor(TitleGradientFrom, false), PlastikHandler::getColor(TitleGradientTo, false), KPixmapEffect::VerticalGradient); - iTitleBarTile = new QPixmap(1, s_titleHeight ); + iTitleBarTile = new QPixmap(1, th ); painter.begin(iTitleBarTile); painter.drawPixmap(0, 0, tempPixmap); painter.end(); @@ -960,7 +698,7 @@ void PlastikClient::delete_pixmaps() void PlastikClient::update_captionBuffer() { - if (!PlastikHandler::initialized()) return; + oldCaption = caption(); const uint maxCaptionLength = 300; // truncate captions longer than this! QString c(caption() ); @@ -972,12 +710,14 @@ void PlastikClient::update_captionBuffer() QFontMetrics fm(s_titleFont); int captionWidth = fm.width(c); + const int th = layoutMetric(LM_TitleHeight, false); + QPixmap textPixmap; QPainter painter; if(PlastikHandler::titleShadow()) { // prepare the shadow - textPixmap = QPixmap(captionWidth+2*2, s_titleHeight ); // 2*2 px shadow space + textPixmap = QPixmap(captionWidth+2*2, th ); // 2*2 px shadow space textPixmap.fill(QColor(0,0,0)); textPixmap.setMask( textPixmap.createHeuristicMask(TRUE) ); painter.begin(&textPixmap); @@ -991,7 +731,7 @@ void PlastikClient::update_captionBuffer() ShadowEngine se; // active - aCaptionBuffer->resize(captionWidth+4, s_titleHeight ); // 4 px shadow + aCaptionBuffer->resize(captionWidth+4, th ); // 4 px shadow painter.begin(aCaptionBuffer); painter.drawTiledPixmap(aCaptionBuffer->rect(), *aTitleBarTile); if(PlastikHandler::titleShadow()) @@ -1011,7 +751,7 @@ void PlastikClient::update_captionBuffer() // inactive - iCaptionBuffer->resize(captionWidth+4, s_titleHeight ); + iCaptionBuffer->resize(captionWidth+4, th ); painter.begin(iCaptionBuffer); painter.drawTiledPixmap(iCaptionBuffer->rect(), *iTitleBarTile); if(PlastikHandler::titleShadow()) @@ -1026,77 +766,4 @@ void PlastikClient::update_captionBuffer() captionBufferDirty = false; } -void PlastikClient::borders( int& left, int& right, int& top, int& bottom ) const -{ - if ((maximizeMode()==MaximizeFull) && !options()->moveResizeMaximizedWindows()) { - left = right = bottom = 0; - top = s_titleHeight; - - // update layout etc. - topSpacer_->changeSize(1, 0, QSizePolicy::Expanding, QSizePolicy::Fixed); - decoSpacer_->changeSize(1, 0, QSizePolicy::Expanding, QSizePolicy::Fixed); - leftSpacer_->changeSize(left, 1, QSizePolicy::Fixed, QSizePolicy::Expanding); - leftTitleSpacer_->changeSize(left, s_titleHeight, QSizePolicy::Fixed, QSizePolicy::Fixed); - rightSpacer_->changeSize(right, 1, QSizePolicy::Fixed, QSizePolicy::Expanding); - rightTitleSpacer_->changeSize(right, s_titleHeight, QSizePolicy::Fixed, QSizePolicy::Fixed); - bottomSpacer_->changeSize(1, bottom, QSizePolicy::Expanding, QSizePolicy::Fixed); - } else { - left = right = bottom = PlastikHandler::borderSize(); - top = s_titleHeight + DECOHEIGHT + TOPMARGIN; - - // update layout etc. - topSpacer_->changeSize(1, TOPMARGIN, QSizePolicy::Expanding, QSizePolicy::Fixed); - decoSpacer_->changeSize(1, DECOHEIGHT, QSizePolicy::Expanding, QSizePolicy::Fixed); - leftSpacer_->changeSize(left, 1, QSizePolicy::Fixed, QSizePolicy::Expanding); - leftTitleSpacer_->changeSize(SIDETITLEMARGIN, s_titleHeight, - QSizePolicy::Fixed, QSizePolicy::Fixed); - rightSpacer_->changeSize(right, 1, QSizePolicy::Fixed, QSizePolicy::Expanding); - rightTitleSpacer_->changeSize(SIDETITLEMARGIN, s_titleHeight, - QSizePolicy::Fixed, QSizePolicy::Fixed); - bottomSpacer_->changeSize(1, bottom, QSizePolicy::Expanding, QSizePolicy::Fixed); - } - - // activate updated layout - widget()->layout()->activate(); -} - -QSize PlastikClient::minimumSize() const -{ - return widget()->minimumSize(); -} - -void PlastikClient::show() -{ - widget()->show(); -} - -void PlastikClient::resize( const QSize& s ) -{ - widget()->resize( s ); -} - -bool PlastikClient::eventFilter( QObject* o, QEvent* e ) -{ - if( o != widget()) - return false; - switch( e->type()) - { - case QEvent::Resize: - resizeEvent(); - return true; - case QEvent::Paint: - paintEvent( static_cast< QPaintEvent* >( e )); - return true; - case QEvent::MouseButtonDblClick: - mouseDoubleClickEvent( static_cast< QMouseEvent* >( e )); - return true; - case QEvent::MouseButtonPress: - processMousePressEvent( static_cast< QMouseEvent* >( e )); - return true; - default: - break; - } - return false; -} - } // KWinPlastik diff --git a/clients/plastik/plastikclient.h b/clients/plastik/plastikclient.h index 09c3ca6f19..0863dba222 100644 --- a/clients/plastik/plastikclient.h +++ b/clients/plastik/plastikclient.h @@ -23,74 +23,41 @@ #ifndef KNIFTYCLIENT_H #define KNIFTYCLIENT_H -#include -#include "plastik.h" +#include -class QSpacerItem; -class QVBoxLayout; -class QBoxLayout; +#include "plastik.h" namespace KWinPlastik { class PlastikButton; -class PlastikClient : public KDecoration +class PlastikClient : public KCommonDecoration { - Q_OBJECT public: PlastikClient(KDecorationBridge* bridge, KDecorationFactory* factory); ~PlastikClient(); - virtual void init(); + virtual QString visibleName() const; + virtual QString defaultButtonsLeft() const; + virtual QString defaultButtonsRight() const; + virtual bool decorationBehaviour(DecorationBehaviour behaviour) const; + virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton * = 0) const; + virtual QRegion cornerShape(WindowCorner corner); + virtual KCommonDecorationButton *createButton(ButtonType type); - virtual void borders( int& left, int& right, int& top, int& bottom ) const; - virtual void resize(const QSize&); - virtual QSize minimumSize() const; - virtual void show(); - virtual bool eventFilter( QObject* o, QEvent* e ); + virtual void init(); + virtual void reset( unsigned long changed ); + + virtual void paintEvent(QPaintEvent *e); + virtual void updateCaption(); QPixmap getTitleBarTile(bool active) const { return active ? *aTitleBarTile : *iTitleBarTile; } -protected: - virtual void resizeEvent(); - virtual void paintEvent(QPaintEvent *e); - virtual void mouseDoubleClickEvent(QMouseEvent *e); - virtual void maximizeChange(); - virtual void desktopChange(); - virtual void shadeChange(); - virtual void doShape(); - - virtual void reset( unsigned long changed ); - - virtual void captionChange(); - virtual void iconChange(); - virtual void activeChange(); - virtual Position mousePosition(const QPoint &point) const; - -private slots: - void keepAboveChange(bool above); - void keepBelowChange(bool below); - void slotMaximize(); - void slotShade(); - void slotKeepAbove(); - void slotKeepBelow(); - void menuButtonPressed(); - void menuButtonReleased(); - bool isTool(); private: - void _resetLayout(); - void addButtons(QBoxLayout* layout, const QString& buttons, int buttonSize = 18); - - QVBoxLayout *mainLayout_; - QSpacerItem *topSpacer_, - *titleSpacer_, - *leftTitleSpacer_, *rightTitleSpacer_, - *decoSpacer_, - *leftSpacer_, *rightSpacer_, - *bottomSpacer_; + QRect captionRect() const; QPixmap *aCaptionBuffer, *iCaptionBuffer; void update_captionBuffer(); @@ -100,14 +67,11 @@ private: void create_pixmaps(); void delete_pixmaps(); - PlastikButton *m_button[NumButtons]; - + QRect m_captionRect; + QString oldCaption; bool captionBufferDirty; - bool closing; - // settings... - int s_titleHeight; QFont s_titleFont; };