diff --git a/clients/oxygen/CMakeLists.txt b/clients/oxygen/CMakeLists.txt index 42d31d367..e3aa38615 100644 --- a/clients/oxygen/CMakeLists.txt +++ b/clients/oxygen/CMakeLists.txt @@ -1,25 +1,24 @@ ########### next target ############### set(kwin_oxy_SRCS lib/helper.cpp - helper.cpp oxygenclient.cpp oxygenbutton.cpp oxygen.cpp definitions.cpp ) kde4_add_plugin(kwin3_oxy ${kwin_oxy_SRCS}) target_link_libraries(kwin3_oxy ${KDE4_KDEFX_LIBS} ${KDE4_KDEUI_LIBS} ${X11_Xrender_LIB} kdecorations) install(TARGETS kwin3_oxy DESTINATION ${PLUGIN_INSTALL_DIR} ) ########### install files ############### install( FILES oxygenclient.desktop DESTINATION ${DATA_INSTALL_DIR}/kwin/ ) diff --git a/clients/oxygen/helper.cpp b/clients/oxygen/helper.cpp deleted file mode 100644 index 78ca31685..000000000 --- a/clients/oxygen/helper.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2007 Matthew Woehlke - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "helper.h" - -#include - -#include - -#include - -OxygenWindecoHelper::OxygenWindecoHelper(const QByteArray &componentName) - : OxygenHelper(componentName) -{ - m_windecoButtonCache.setMaxCost(64); -} - -QPixmap OxygenWindecoHelper::windecoButton(const QColor &color, int size) -{ - quint64 key = (quint64(color.rgba()) << 32) | size; - QPixmap *pixmap = m_windecoButtonCache.object(key); - - if (!pixmap) - { - pixmap = new QPixmap(size, (int)ceil(double(size)*10.0/9.0)); - pixmap->fill(QColor(0,0,0,0)); - - QPainter p(pixmap); - p.setRenderHints(QPainter::Antialiasing); - p.setPen(Qt::NoPen); - p.setWindow(0,0,18,20); - - QColor light = calcLightColor(color); - QColor dark = calcDarkColor(color); - - // shadow - drawShadow(p, calcShadowColor(color), 18); - - // bevel - qreal y = KColorUtils::luma(color); - qreal yl = KColorUtils::luma(light); - qreal yd = KColorUtils::luma(light); - QLinearGradient bevelGradient(0, 0, 0, 18); - bevelGradient.setColorAt(0.45, light); - bevelGradient.setColorAt(0.80, dark); - if (y < yl && y > yd) // no middle when color is very light/dark - bevelGradient.setColorAt(0.55, color); - p.setBrush(QBrush(bevelGradient)); - p.drawEllipse(QRectF(2.0,2.0,14.0,14.0)); - - // inside mask - QRadialGradient maskGradient(9,9,7,9,9); - maskGradient.setColorAt(0.70, QColor(0,0,0,0)); - maskGradient.setColorAt(0.85, QColor(0,0,0,140)); - maskGradient.setColorAt(0.95, QColor(0,0,0,255)); - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.setBrush(maskGradient); - p.drawRect(0,0,20,20); - - // inside - QLinearGradient innerGradient(0, 3, 0, 15); - innerGradient.setColorAt(0.0, color); - innerGradient.setColorAt(1.0, light); - p.setCompositionMode(QPainter::CompositionMode_DestinationOver); - p.setBrush(innerGradient); - p.drawEllipse(QRectF(2.0,2.0,14.0,14.0)); - - // anti-shadow - QRadialGradient highlightGradient(9,8.5,8,9,8.5); - highlightGradient.setColorAt(0.85, alphaColor(light, 0.0)); - highlightGradient.setColorAt(1.00, light); - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - p.setBrush(highlightGradient); - p.drawEllipse(QRectF(2.0,2.0,14.0,14.0)); - - m_windecoButtonCache.insert(key, pixmap); - } - - return *pixmap; -} diff --git a/clients/oxygen/helper.h b/clients/oxygen/helper.h deleted file mode 100644 index 3bcb28986..000000000 --- a/clients/oxygen/helper.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2007 Matthew Woehlke - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __OXYGEN_WINDECO_HELPER_H -#define __OXYGEN_WINDECO_HELPER_H - -#include "lib/helper.h" - -class OxygenWindecoHelper : public OxygenHelper -{ -public: - explicit OxygenWindecoHelper(const QByteArray &componentName); - virtual ~OxygenWindecoHelper() {} - - QPixmap windecoButton(const QColor &color, int size); - -protected: - QCache m_windecoButtonCache; -}; - -#endif // __OXYGEN_WINDECO_HELPER_H diff --git a/clients/oxygen/oxygenbutton.cpp b/clients/oxygen/oxygenbutton.cpp index d178f50cc..288504192 100644 --- a/clients/oxygen/oxygenbutton.cpp +++ b/clients/oxygen/oxygenbutton.cpp @@ -1,152 +1,177 @@ ////////////////////////////////////////////////////////////////////////////// // 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 "helper.h" +#include "lib/helper.h" namespace Oxygen { -K_GLOBAL_STATIC_WITH_ARGS(OxygenWindecoHelper, globalHelper, ("OxygenDeco")) +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) { 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.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: + 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); + break; + case ButtonClose: + painter.drawLine(6,6,12,12); + painter.drawLine(12,6,6,12); + break; + } } } //namespace Oxygen