1 /***************************************************************************** 2 * Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com> * 3 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU Lesser General Public License as * 7 * published by the Free Software Foundation; either version 2.1 of the * 8 * License, or (at your option) version 3, or any later version accepted * 9 * by the membership of KDE e.V. (or its successor approved by the * 10 * membership of KDE e.V.), which shall act as a proxy defined in * 11 * Section 6 of version 3 of the license. * 12 * * 13 * This program is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 16 * Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public * 19 * License along with this library. If not, * 20 * see <http://www.gnu.org/licenses/>. * 21 *****************************************************************************/ 22 /* 23 based on the window decoration "Plastik": 24 Copyright (C) 2003-2005 Sandro Giessl <sandro@giessl.com> 25 26 based on the window decoration "Web": 27 Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> 28 */ 29 30 #ifndef QTCURVEBUTTON_H 31 #define QTCURVEBUTTON_H 32 33 #include <QImage> 34 #include "qtcurvehandler.h" 35 #include <kcommondecoration.h> 36 37 class QTimer; 38 class QStyle; 39 40 namespace QtCurve { 41 namespace KWin { 42 43 class QtCurveClient; 44 45 class QtCurveButton: public KCommonDecorationButton { 46 public: 47 QtCurveButton(ButtonType type, QtCurveClient *parent); ~QtCurveButton()48 ~QtCurveButton() {} 49 50 void reset(unsigned long changed); 51 QtCurveClient* client()52 client() 53 { 54 return m_client; 55 } 56 57 protected: 58 void paintEvent(QPaintEvent *); 59 60 private: 61 void enterEvent(QEvent *e); 62 void leaveEvent(QEvent *e); 63 void drawButton(QPainter *painter); 64 void updateMask(); 65 66 private: 67 QtCurveClient *m_client; 68 ButtonIcon m_iconType; 69 bool m_hover; 70 71 friend class IconEngine; 72 }; 73 74 /** 75 * This class creates bitmaps which can be used as icons on buttons. The icons 76 * are "hardcoded". 77 * Over the previous "Gimp->xpm->QImage->recolor->SmoothScale->QPixmap" solution 78 * it has the important advantage that icons are more scalable and at the same 79 * time sharp and not blurred. 80 */ 81 class IconEngine { 82 public: 83 static QBitmap icon(ButtonIcon icon, int size, QStyle *style); 84 85 private: 86 enum Object { 87 HorizontalLine, 88 VerticalLine, 89 DiagonalLine, 90 CrossDiagonalLine 91 }; 92 93 static void drawObject(QPainter &p, Object object, int x, int y, 94 int length, int lineWidth); 95 }; 96 97 } 98 } 99 100 #endif 101