diff --git a/clients/oxygen/oxygenbutton.cpp b/clients/oxygen/oxygenbutton.cpp index 288504192..d7d7bfd8d 100644 --- a/clients/oxygen/oxygenbutton.cpp +++ b/clients/oxygen/oxygenbutton.cpp @@ -1,177 +1,191 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenbutton.cpp // ------------------- // Oxygen window decoration for KDE. Buttons. // ------------------- // Copyright (c) 2006, 2007 Riccardo Iaconelli // Copyright (c) 2006, 2007 Casper Boemann // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include "oxygenclient.h" #include "oxygenbutton.h" #include "oxygen.h" #include "definitions.cpp" #include "lib/helper.h" namespace Oxygen { K_GLOBAL_STATIC_WITH_ARGS(OxygenHelper, globalHelper, ("OxygenDeco")) // class OxygenClient; /* extern int BUTTONSIZE; extern int DECOSIZE;*/ // static const int BUTTONSIZE = 18; // static const int DECOSIZE = 8; ////////////////////////////////////////////////////////////////////////////// // OxygenButton Class // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // OxygenButton() // --------------- // Constructor OxygenButton::OxygenButton(OxygenClient *parent, - const QString& tip, ButtonType type, - const unsigned char *bitmap) - : QAbstractButton(parent->widget()), client_(parent), type_(type), - lastmouse_(0) + const QString& tip, ButtonType type) + : KCommonDecorationButton((::ButtonType)type,(KCommonDecoration*) parent) + , client_(parent) + , type_(type) + , lastmouse_(0) { setAutoFillBackground(false); setAttribute(Qt::WA_OpaquePaintEvent, false); setFixedSize(BUTTONSIZE, BUTTONSIZE); setCursor(Qt::ArrowCursor); setToolTip(tip); } OxygenButton::~OxygenButton() { } ////////////////////////////////////////////////////////////////////////////// // sizeHint() // ---------- // Return size hint QSize OxygenButton::sizeHint() const { return QSize(BUTTONSIZE, BUTTONSIZE); } ////////////////////////////////////////////////////////////////////////////// // enterEvent() // ------------ // Mouse has entered the button void OxygenButton::enterEvent(QEvent *e) { // if we wanted to do mouseovers, we would keep track of it here if (status_ != Oxygen::Pressed) { status_ = Oxygen::Hovered; } QAbstractButton::enterEvent(e); } ////////////////////////////////////////////////////////////////////////////// // leaveEvent() // ------------ // Mouse has left the button void OxygenButton::leaveEvent(QEvent *e) { // if we wanted to do mouseovers, we would keep track of it here status_ = Oxygen::Normal; QAbstractButton::leaveEvent(e); } ////////////////////////////////////////////////////////////////////////////// // pressSlot() // ------------ // Mouse has pressed the button void OxygenButton::pressSlot() { - kDebug() << "Pressed "; status_ = Oxygen::Pressed; update(); } ////////////////////////////////////////////////////////////////////////////// // drawButton() // ------------ // Draw the button void OxygenButton::paintEvent(QPaintEvent *) { QPainter painter(this); if (type_ == ButtonMenu) { // we paint the mini icon (which is 16 pixels high) int dx = (width() - 16) / 2; int dy = (height() - 16) / 2; painter.drawPixmap(dx, dy, client_->icon().pixmap(16)); return; } QColor bg = globalHelper->backgroundTopColor(palette().window()); painter.drawPixmap(0, 0, globalHelper->windecoButton(palette().button(), BUTTONSIZE)); painter.setRenderHints(QPainter::Antialiasing); painter.setBrush(Qt::NoBrush); QLinearGradient lg(0, 6, 0, 12); lg.setColorAt(0.45, QColor(0,0,0,150)); lg.setColorAt(0.80, QColor(0,0,0,80)); painter.setPen(QPen(lg,2)); switch(type_) { case ButtonSticky: + painter.drawPoint(9,9); + break; case ButtonHelp: break; case ButtonMin: painter.drawLine(6,8,9,11); painter.drawLine(9,11,12,8); break; case ButtonMax: - painter.drawLine(9,8,12,11); - painter.drawLine(6,11,9,8); + switch(client_->maximizeMode()) + { + case OxygenClient::MaximizeRestore: + case OxygenClient::MaximizeVertical: + case OxygenClient::MaximizeHorizontal: + painter.drawLine(9,8,12,11); + painter.drawLine(6,11,9,8); + break; + case OxygenClient::MaximizeFull: + painter.drawLine(6,9,12,9); + break; + } break; case ButtonClose: painter.drawLine(6,6,12,12); painter.drawLine(12,6,6,12); break; + default: + break; } } } //namespace Oxygen diff --git a/clients/oxygen/oxygenbutton.h b/clients/oxygen/oxygenbutton.h index 4d9403351..277cf14a5 100644 --- a/clients/oxygen/oxygenbutton.h +++ b/clients/oxygen/oxygenbutton.h @@ -1,74 +1,73 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenbutton.h // ------------------- // Oxygen window decoration for KDE. Buttons. // ------------------- // Copyright (c) 2006, 2007 Riccardo Iaconelli // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// // class QAbstractButton; #ifndef OXYGENBUTTON_H #define OXYGENBUTTON_H -#include +#include #include "oxygen.h" namespace Oxygen { class OxygenClient; enum ButtonStatus { Normal, Hovered, Pressed }; Q_DECLARE_FLAGS(ButtonState, ButtonStatus) -class OxygenButton : public QAbstractButton +class OxygenButton : public KCommonDecorationButton { public: explicit OxygenButton(OxygenClient *parent=0, const QString &tip=NULL, - ButtonType type=ButtonHelp, - const unsigned char *bitmap=0); + ButtonType type=ButtonHelp); ~OxygenButton(); QSize sizeHint() const; const int lastMousePress(){return lastmouse_;} - void reset(){repaint();} + void reset(long unsigned int){repaint();} private: void enterEvent(QEvent *e); void leaveEvent(QEvent *e); void paintEvent(QPaintEvent *e); private Q_SLOTS: void pressSlot(); private: OxygenClient *client_; ButtonType type_; ButtonState status_; int lastmouse_; }; } //namespace Oxygen #endif diff --git a/clients/oxygen/oxygenclient.cpp b/clients/oxygen/oxygenclient.cpp index 516340bd9..bf0ed343a 100644 --- a/clients/oxygen/oxygenclient.cpp +++ b/clients/oxygen/oxygenclient.cpp @@ -1,646 +1,361 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenclient.cpp // ------------------- // Oxygen window decoration for KDE // ------------------- // Copyright (c) 2003, 2004 David Johnson // Copyright (c) 2006, 2007 Casper Boemann // Copyright (c) 2006, 2007 Riccardo Iaconelli // // Please see the header file for copyright and license information. ////////////////////////////////////////////////////////////////////////////// // #ifndef OXYGENCLIENT_H // #define OXYGENCLIENT_H #include #include #include #include #include #include #include #include #include //Added by qt3to4: #include #include #include #include #include #include #include #include #include #include #include "lib/helper.h" #include "oxygenclient.h" #include "oxygenclient.moc" #include "oxygenbutton.h" #include "oxygen.h" #include "definitions.cpp" namespace Oxygen { // global constants // static const int BUTTONSIZE = 18; // static const int DECOSIZE = 8; // static const int TITLESIZE = 18; // static const int TFRAMESIZE = 8; // static const int BFRAMESIZE = 7; // static const int LFRAMESIZE = 8; // static const int RFRAMESIZE = 7;BUTTONSIZE // static const int FRAMEBUTTONSPACE = 67; K_GLOBAL_STATIC_WITH_ARGS(OxygenHelper, globalHelper, ("OxygenDeco")) void renderDot(QPainter *p, const QPointF &point, qreal diameter) { p->drawEllipse(QRectF(point.x()-diameter/2, point.y()-diameter/2, diameter, diameter)); } -// window button decorations -static const unsigned char close_bits[] = { - 0xc3, 0x66, 0x7e, 0x3c, 0x3c, 0x7e, 0x66, 0xc3}; - -static const unsigned char help_bits[] = { - 0x7e, 0x7e, 0x60, 0x78, 0x78, 0x00, 0x18, 0x18}; - -static const unsigned char max_bits[] = { - 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00}; - -static const unsigned char min_bits[] = { -// 0x00, 0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00}; - 0x00, 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00}; - -static const unsigned char minmax_bits[] = { - 0x00, 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e, 0x00}; - -static const unsigned char stickydown_bits[] = { - 0x00, 0x18, 0x18, 0x7e, 0x7e, 0x18, 0x18, 0x00}; - -static const unsigned char sticky_bits[] = { - 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00}; - ////////////////////////////////////////////////////////////////////////////// // OxygenClient Class // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // OxygenClient() // --------------- // Constructor OxygenClient::OxygenClient(KDecorationBridge *b, KDecorationFactory *f) - : KDecoration(b, f) { ; } + : KCommonDecoration(b, f) { ; } OxygenClient::~OxygenClient() { - for (int n=0; nsetAutoFillBackground(false); - widget()->setAttribute(Qt::WA_OpaquePaintEvent); - widget()->setAttribute( Qt::WA_PaintOnScreen, false); - widget()->installEventFilter(this); - - // setup layout - QGridLayout *mainlayout = new QGridLayout(widget()); - QHBoxLayout *titlelayout = new QHBoxLayout(); - // Force button size to be in a reasonable range. - // If the frame width is large, the button size must be large too. - titleBarHeight = (QFontMetrics(options()->font(true)).height() + 1) & 0x3e; - if (titleBarHeight < TITLESIZE) titleBarHeight = TITLESIZE; - - titlebar_ = new QSpacerItem(1, titleBarHeight, QSizePolicy::Expanding, - QSizePolicy::Fixed); - - mainlayout->addItem(new QSpacerItem(LFRAMESIZE, TFRAMESIZE), 0, 0); - mainlayout->addItem(new QSpacerItem(0, BFRAMESIZE), 3, 0); - mainlayout->addItem(new QSpacerItem(RFRAMESIZE, 0), 0, 2); - - mainlayout->addLayout(titlelayout, 1, 1); - if (isPreview()) { - QWidget *previewWidget = new QLabel(i18n("
Oxygen preview! =)
"), widget()); - previewWidget->setAutoFillBackground(true); - mainlayout->addWidget(previewWidget, 2, 1); - } else { - mainlayout->addItem(new QSpacerItem(0, 0), 2, 1); - } - - mainlayout->setRowStretch(2, 10); - mainlayout->setColumnStretch(1, 10); - - // setup titlebar buttons - for (int n=0; ntitleButtonsLeft()); - titlelayout->addItem(titlebar_); - addButtons(titlelayout, options()->titleButtonsRight()); - titlelayout->addSpacing(2); - - titlelayout->setSpacing(0); - titlelayout->setMargin(0); - mainlayout->setSpacing(0); - mainlayout->setMargin(0); + return i18n("Oxygen"); } -////////////////////////////////////////////////////////////////////////////// -// addButtons() -// ------------ -// Add buttons to title layout - -void OxygenClient::addButtons(QHBoxLayout *layout, const QString& s) +QString OxygenClient::defaultButtonsLeft() const { - const unsigned char *bitmap; - QString tip; - - if (s.length() > 0) { - for (int n=0; n < s.length(); n++) { - if(n>0) - layout->addSpacing(3); - switch (s[n].toLatin1()) { - case 'M': // Menu button - if (!button[ButtonMenu]) { - button[ButtonMenu] = - new OxygenButton(this, i18n("Menu"), ButtonMenu, 0); - connect(button[ButtonMenu], SIGNAL(pressed()), - this, SLOT(menuButtonPressed())); - layout->addWidget(button[ButtonMenu]); - } - break; - - case 'S': // Sticky button - if (!button[ButtonSticky]) { - if (isOnAllDesktops()) { - bitmap = stickydown_bits; - tip = i18n("Un-Sticky"); - } else { - bitmap = sticky_bits; - tip = i18n("Sticky"); - } - button[ButtonSticky] = - new OxygenButton(this, tip, ButtonSticky, bitmap); - connect(button[ButtonSticky], SIGNAL(clicked()), - this, SLOT(toggleOnAllDesktops())); - layout->addWidget(button[ButtonSticky]); - } - break; - - case 'H': // Help button - if ((!button[ButtonHelp]) && providesContextHelp()) { - button[ButtonHelp] = - new OxygenButton(this, i18n("Help"), ButtonHelp, help_bits); - connect(button[ButtonHelp], SIGNAL(clicked()), - this, SLOT(showContextHelp())); - layout->addWidget(button[ButtonHelp]); - } - break; - - case 'I': // Minimize button - if ((!button[ButtonMin]) && isMinimizable()) { - button[ButtonMin] = - new OxygenButton(this, i18n("Minimize"), ButtonMin, min_bits); - connect(button[ButtonMin], SIGNAL(clicked()), - this, SLOT(minimize())); - layout->addWidget(button[ButtonMin]); - } - break; - - case 'A': // Maximize button - if ((!button[ButtonMax]) && isMaximizable()) { - if (maximizeMode() == MaximizeFull) { - bitmap = minmax_bits; - tip = i18n("Restore"); - } else { - bitmap = max_bits; - tip = i18n("Maximize"); - } - button[ButtonMax] = - new OxygenButton(this, tip, ButtonMax, bitmap); - connect(button[ButtonMax], SIGNAL(clicked()), - this, SLOT(maxButtonPressed())); - layout->addWidget(button[ButtonMax]); - } - break; - - case 'X': // Close button - if ((!button[ButtonClose]) && isCloseable()) { - button[ButtonClose] = - new OxygenButton(this, i18n("Close"), ButtonClose, close_bits); - connect(button[ButtonClose], SIGNAL(clicked()), - this, SLOT(closeWindow())); - layout->addWidget(button[ButtonClose]); - } - break; - - case '_': // Spacer item - layout->addSpacing(FRAMEBUTTONSPACE); - } - } - } + return "M"; } -////////////////////////////////////////////////////////////////////////////// -// activeChange() -// -------------- -// window active state has changed - -void OxygenClient::activeChange() +QString OxygenClient::defaultButtonsRight() const { - for (int n=0; nreset(); - widget()->repaint(); + return "HIAX"; } -////////////////////////////////////////////////////////////////////////////// -// captionChange() -// --------------- -// The title has changed - -void OxygenClient::captionChange() +void OxygenClient::init() { - widget()->repaint(titlebar_->geometry()); -} + KCommonDecoration::init(); -////////////////////////////////////////////////////////////////////////////// -// desktopChange() -// --------------- -// Called when desktop/sticky changes + widget()->setAutoFillBackground(false); + widget()->setAttribute(Qt::WA_OpaquePaintEvent); + widget()->setAttribute( Qt::WA_PaintOnScreen, false); +} -void OxygenClient::desktopChange() +bool OxygenClient::decorationBehaviour(DecorationBehaviour behaviour) const { - bool d = isOnAllDesktops(); - if (button[ButtonSticky]) { - button[ButtonSticky]->setToolTip( d ? i18n("Un-Sticky") : i18n("Sticky")); - } -} + switch (behaviour) { + case DB_MenuClose: + return true;//Handler()->menuClose(); -////////////////////////////////////////////////////////////////////////////// -// iconChange() -// ------------ -// The title has changed + case DB_WindowMask: + return false; -void OxygenClient::iconChange() -{ - if (button[ButtonMenu]) { - button[ButtonMenu]->repaint(); + default: + return KCommonDecoration::decorationBehaviour(behaviour); } } -////////////////////////////////////////////////////////////////////////////// -// maximizeChange() -// ---------------- -// Maximized state has changed - -void OxygenClient::maximizeChange() +int OxygenClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const { - bool m = (maximizeMode() == MaximizeFull); - if (button[ButtonMax]) { - button[ButtonMax]->setToolTip(m ? i18n("Restore") : i18n("Maximize")); - } -} + bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows(); + + switch (lm) { + case LM_BorderLeft: + case LM_BorderRight: + case LM_BorderBottom: + { + if (respectWindowState && maximized) { + return 0; + } else { + return BFRAMESIZE; + } + } -////////////////////////////////////////////////////////////////////////////// -// shadeChange() -// ------------- -// Called when window shading changes + case LM_TitleEdgeTop: + { + if (respectWindowState && maximized) { + return 0; + } else { + return TFRAMESIZE; + } + } -void OxygenClient::shadeChange() -{ ; } + case LM_TitleEdgeBottom: + { + return 0; + } -////////////////////////////////////////////////////////////////////////////// -// borders() -// ---------- -// Get the size of the borders + case LM_TitleEdgeLeft: + case LM_TitleEdgeRight: + { + if (respectWindowState && maximized) { + return 0; + } else { + return 6; + } + } -void OxygenClient::borders(int &l, int &r, int &t, int &b) const -{ - l = LFRAMESIZE; - r = RFRAMESIZE; - t = titleBarHeight + TFRAMESIZE; - b = BFRAMESIZE; -} + case LM_TitleBorderLeft: + case LM_TitleBorderRight: + return 5; + + case LM_ButtonWidth: + case LM_ButtonHeight: + case LM_TitleHeight: + { + if (respectWindowState && isToolWindow()) { + return BUTTONSIZE; + } else { + return BUTTONSIZE; + } + } -////////////////////////////////////////////////////////////////////////////// -// resize() -// -------- -// Called to resize the window + case LM_ButtonSpacing: + return 1; -void OxygenClient::resize(const QSize &size) -{ - widget()->resize(size); -} + case LM_ButtonMarginTop: + return 0; -////////////////////////////////////////////////////////////////////////////// -// minimumSize() -// ------------- -// Return the minimum allowable size for this window + case LM_ExplicitButtonSpacer: + return 3; -QSize OxygenClient::minimumSize() const -{ - return widget()->minimumSize(); + default: + return KCommonDecoration::layoutMetric(lm, respectWindowState, btn); + } } -////////////////////////////////////////////////////////////////////////////// -// mousePosition() -// --------------- -// Return logical mouse position -KDecoration::Position OxygenClient::mousePosition(const QPoint &point) const +KCommonDecorationButton *OxygenClient::createButton(::ButtonType type) { - const int corner = 24; - Position pos; - - if (point.y() <= TFRAMESIZE) { - // inside top frame - if (point.x() <= corner) pos = PositionTopLeft; - else if (point.x() >= (width()-corner)) pos = PositionTopRight; - else pos = PositionTop; - } else if (point.y() >= (height()-BFRAMESIZE)) { - // inside handle - if (point.x() <= corner) pos = PositionBottomLeft; - else if (point.x() >= (width()-corner)) pos = PositionBottomRight; - else pos = PositionBottom; - } else if (point.x() <= LFRAMESIZE) { - // on left frame - if (point.y() <= corner) pos = PositionTopLeft; - else if (point.y() >= (height()-corner)) pos = PositionBottomLeft; - else pos = PositionLeft; - } else if (point.x() >= width()-RFRAMESIZE) { - // on right frame - if (point.y() <= corner) pos = PositionTopRight; - else if (point.y() >= (height()-corner)) pos = PositionBottomRight; - else pos = PositionRight; - } else { - // inside the frame - pos = PositionCenter; - } - return pos; -} + switch (type) { + case MenuButton: + return new OxygenButton(this, i18n("Menu"), ButtonMenu); -////////////////////////////////////////////////////////////////////////////// -// eventFilter() -// ------------- -// Event filter + case HelpButton: + return new OxygenButton(this, i18n("Help"), ButtonHelp); -bool OxygenClient::eventFilter(QObject *obj, QEvent *e) -{ - if (obj != widget()) return false; - - switch (e->type()) { - case QEvent::MouseButtonDblClick: { - mouseDoubleClickEvent(static_cast(e)); - return true; - } - case QEvent::MouseButtonPress: { - processMousePressEvent(static_cast(e)); - return true; - } - case QEvent::Paint: { - paintEvent(static_cast(e)); - return true; - } - case QEvent::Show: { - showEvent(static_cast(e)); - return true; - } - default: { - return false; - } - } + case MinButton: + return new OxygenButton(this, i18n("Minimize"), ButtonMin); - return false; -} + case MaxButton: + return new OxygenButton(this, i18n("Minimize"), ButtonMax); -////////////////////////////////////////////////////////////////////////////// -// mouseDoubleClickEvent() -// ----------------------- -// Doubleclick on title + case CloseButton: + return new OxygenButton(this, i18n("Minimize"), ButtonClose); -void OxygenClient::mouseDoubleClickEvent(QMouseEvent *e) -{ - if (titlebar_->geometry().contains(e->pos())) titlebarDblClickOperation(); + default: + return 0; + } } + ////////////////////////////////////////////////////////////////////////////// // paintEvent() // ------------ // Repaint the window void OxygenClient::paintEvent(QPaintEvent *e) { Q_UNUSED(e) if (!OxygenFactory::initialized()) return; doShape(); QPalette palette = widget()->palette(); QPainter painter(widget()); // ### - This feels like a kwin bug; the palette we get back always seems // to be (incorrectly) using the Inactive group, which is wrong; active // windows should have currentColorGroup() == Active. So, hack around it... // I don't think a window can be disabled? if (isActive()) palette.setCurrentColorGroup(QPalette::Active); else palette.setCurrentColorGroup(QPalette::Inactive); - QRect title(titlebar_->geometry()); - int x,y,w,h; QRect frame = widget()->frameGeometry(); QColor color = palette.window(); -//color = QColor(Qt::red); -/* - - QLinearGradient gradient(0, 0, 0, frame.height()); - gradient.setColorAt(0, color.lighter(110)); - gradient.setColorAt(1, color.darker(110)); - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(QRect(0, 0, frame.width(), TITLESIZE + TFRAMESIZE), gradient); - painter.fillRect(QRect(0, 0, LFRAMESIZE, frame.height()), gradient); - painter.fillRect(QRect(0, frame.height() - BFRAMESIZE -1, - frame.width(), BFRAMESIZE), gradient); - painter.fillRect(QRect(frame.width()-RFRAMESIZE, 0, - RFRAMESIZE, frame.height()), gradient); - -*/ + + const int titleHeight = layoutMetric(LM_TitleHeight); + const int titleTop = layoutMetric(LM_TitleEdgeTop) + frame.top(); + const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft); + const int marginLeft = layoutMetric(LM_TitleBorderLeft); + const int marginRight = layoutMetric(LM_TitleBorderRight); + + const int titleLeft = frame.left() + titleEdgeLeft + buttonsLeftWidth() + marginLeft; + const int titleWidth = frame.width() - + titleEdgeLeft - layoutMetric(LM_TitleEdgeRight) - + buttonsLeftWidth() - buttonsRightWidth() - + marginLeft - marginRight; + int splitY = qMin(300, 3*frame.height()/4); QPixmap tile = globalHelper->verticalGradient(color, splitY); - painter.drawTiledPixmap(QRect(0, 0, frame.width(), titleBarHeight + TFRAMESIZE), tile); + painter.drawTiledPixmap(QRect(0, 0, frame.width(), titleHeight + TFRAMESIZE), tile); painter.drawTiledPixmap(QRect(0, 0, LFRAMESIZE, splitY), tile); painter.fillRect(0, splitY, LFRAMESIZE, frame.height() - splitY, globalHelper->backgroundBottomColor(color)); painter.drawTiledPixmap(QRect(frame.width()-RFRAMESIZE, 0, RFRAMESIZE, splitY), tile, QPoint(frame.width()-RFRAMESIZE, 0)); painter.fillRect(frame.width()-RFRAMESIZE, splitY, RFRAMESIZE, frame.height() - splitY, globalHelper->backgroundBottomColor(color)); painter.fillRect(0, frame.height() - BFRAMESIZE, frame.width(), BFRAMESIZE, globalHelper->backgroundBottomColor(color)); int radialW = qMin(600, frame.width()); tile = globalHelper->radialGradient(color, radialW); QRect radialRect = QRect((frame.width() - radialW) / 2, 0, radialW, 64); painter.drawPixmap(radialRect, tile); //painter.setRenderHint(QPainter::Antialiasing,true); // draw title text painter.setFont(options()->font(isActive(), false)); painter.setBrush(palette.windowText()); - painter.drawText(title.x(), title.y(), title.width(), title.height(), + painter.drawText(titleLeft, titleTop, titleWidth, titleHeight, OxygenFactory::titleAlign() | Qt::AlignVCenter, caption()); painter.setRenderHint(QPainter::Antialiasing); // shadows of the frame frame = widget()->rect(); frame.getRect(&x, &y, &w, &h); painter.setBrush(Qt::NoBrush); QLinearGradient lg(0, 0, 0, 10); QGradientStops stops; stops << QGradientStop( 0, QColor(255,255,255, 110) ) << QGradientStop( 1, QColor(128,128,128, 60) ); lg.setStops(stops); painter.setPen(QPen(QBrush(lg),1)); painter.drawLine(QPointF(6.3, 0.5), QPointF(w-6.3, 0.5)); painter.drawArc(QRectF(0.5, 0.5, 9.5, 9.5),90*16, 90*16); painter.drawArc(QRectF(w-9.5-0.5, 0.5, 9.5, 9.5), 0, 90*16); painter.setPen(QColor(128,128,128, 60)); painter.drawLine(QPointF(0.5, 6.3), QPointF(0.5, h-6.3)); painter.drawLine(QPointF(w-0.5, 6.3), QPointF(w-0.5, h-6.3)); lg = QLinearGradient(0, h-10, 0, h); stops.clear(); stops << QGradientStop( 0, QColor(128,128,128, 60) ) << QGradientStop( 1, QColor(0,0,0, 50) ); lg.setStops(stops); painter.setPen(QPen(QBrush(lg),1)); painter.drawArc(QRectF(0.5, h-9.5-0.5, 9.5, 9.5),180*16, 90*16); painter.drawArc(QRectF(w-9.5-0.5, h-9.5-0.5, 9.5, 9.5), 270*16, 90*16); painter.drawLine(QPointF(6.3, h-0.5), QPointF(w-6.3, h-0.5)); qreal cenY = frame.height() / 2 + 0.5; qreal posX = frame.width() - 2.5; painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 66)); renderDot(&painter, QPointF(posX, cenY - 5), 2.5); renderDot(&painter, QPointF(posX, cenY), 2.5); renderDot(&painter, QPointF(posX, cenY + 5), 2.5); painter.translate(frame.width()-9, frame.height()-9); renderDot(&painter, QPointF(0.5, 6.5), 2.5); renderDot(&painter, QPointF(5.5, 5.5), 2.5); renderDot(&painter, QPointF(6.5, 0.5), 2.5); } void OxygenClient::doShape() { int r=widget()->width(); int b=widget()->height(); QRegion mask(0,0,r,b); // Remove top-left corner. mask -= QRegion(0, 0, 3, 1); mask -= QRegion(0, 1, 2, 1); mask -= QRegion(0, 2, 1, 1); // Remove top-right corner. mask -= QRegion(r - 3, 0, 3, 1); mask -= QRegion(r - 2, 1, 2, 1); mask -= QRegion(r - 1, 2, 1, 1); // Remove bottom-left corner. mask -= QRegion(0, b-1-0, 3, b-1-1); mask -= QRegion(0, b-1-1, 2, b-1-1); mask -= QRegion(0, b-1-2, 1, b-1-1); // Remove bottom-right corner. mask -= QRegion(r - 3, b-1-0, 3, b-1-1); mask -= QRegion(r - 2, b-1-1, 2, b-1-1); mask -= QRegion(r - 1, b-1-2, 1, b-1-1); setMask(mask); } -////////////////////////////////////////////////////////////////////////////// -// showEvent() -// ----------- -// Window is being shown - -void OxygenClient::showEvent(QShowEvent *) -{ - widget()->repaint(); -} - -////////////////////////////////////////////////////////////////////////////// -// maxButtonPressed() -// ----------------- -// Max button was pressed - -void OxygenClient::maxButtonPressed() -{ - if (button[ButtonMax]) { - switch (button[ButtonMax]->lastMousePress()) { - case Qt::MidButton: - maximize(maximizeMode() ^ MaximizeVertical); - break; - case Qt::RightButton: - maximize(maximizeMode() ^ MaximizeHorizontal); - break; - default: - (maximizeMode() == MaximizeFull) ? maximize(MaximizeRestore) - : maximize(MaximizeFull); - } - } -} - -////////////////////////////////////////////////////////////////////////////// -// menuButtonPressed() -// ------------------- -// Menu button was pressed (popup the menu) - -void OxygenClient::menuButtonPressed() -{ - if (button[ButtonMenu]) { - QPoint p(button[ButtonMenu]->rect().bottomLeft().x(), - button[ButtonMenu]->rect().bottomLeft().y()); - KDecorationFactory* f = factory(); - showWindowMenu(button[ButtonMenu]->mapToGlobal(p)); - if (!f->exists(this)) return; // decoration was destroyed - button[ButtonMenu]->setDown(false); - } -} - } //namespace Oxygen //#include "oxygenclient.moc" // #endif diff --git a/clients/oxygen/oxygenclient.h b/clients/oxygen/oxygenclient.h index e12848850..09758b81e 100644 --- a/clients/oxygen/oxygenclient.h +++ b/clients/oxygen/oxygenclient.h @@ -1,105 +1,64 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenclient.h // ------------------- // Oxygen window decoration for KDE // ------------------- // Copyright (c) 2003, 2004 David Johnson // Copyright (c) 2006, 2007 Riccardo Iaconelli // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #ifndef OXYGENCLIENT_H #define OXYGENCLIENT_H -// #include -#include -//Added by qt3to4: -#include -#include -#include -#include -#include -#include -#include + +#include #include "oxygenbutton.h" -// #include "oxygen.h" -class QSpacerItem; class QPoint; namespace Oxygen { -// class OxygenClient; -class OxygenButton; -// OxygenButton ////////////////////////////////////////////////////////////// - - - -// inline int OxygenButton::lastMousePress() const -// { return lastmouse_; } -// -// inline void OxygenButton::reset() -// { repaint(); } - -// OxygenClient ////////////////////////////////////////////////////////////// - -class OxygenClient : public KDecoration +class OxygenClient : public KCommonDecoration { Q_OBJECT public: OxygenClient(KDecorationBridge *b, KDecorationFactory *f); virtual ~OxygenClient(); - virtual void init(); - - virtual void activeChange(); - virtual void desktopChange(); - virtual void captionChange(); - virtual void iconChange(); - virtual void maximizeChange(); - virtual void shadeChange(); + virtual QString visibleName() const; + virtual QString defaultButtonsLeft() const; + virtual QString defaultButtonsRight() const; + virtual KCommonDecorationButton *createButton(::ButtonType type); + virtual bool decorationBehaviour(DecorationBehaviour behaviour) const; + virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton * = 0) const; - virtual void borders(int &l, int &r, int &t, int &b) const; - virtual void resize(const QSize &size); - virtual QSize minimumSize() const; - virtual Position mousePosition(const QPoint &point) const; + virtual void init(); private: - void addButtons(QHBoxLayout* layout, const QString& buttons); - - bool eventFilter(QObject *obj, QEvent *e); - void mouseDoubleClickEvent(QMouseEvent *e); void paintEvent(QPaintEvent *e); - void showEvent(QShowEvent *); void doShape(); -private slots: - void maxButtonPressed(); - void menuButtonPressed(); - -private: - OxygenButton *button[ButtonTypeCount]; - QSpacerItem *titlebar_; }; } // namespace Oxygen #endif // EXAMPLECLIENT_H