File indexing completed on 2024-04-28 17:04:37

0001 /*****************************************************************************
0002  *   Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 /*
0023   based on the window decoration "Plastik":
0024   Copyright (C) 2003-2005 Sandro Giessl <sandro@giessl.com>
0025 
0026   based on the window decoration "Web":
0027   Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
0028  */
0029 
0030 #ifndef QTCURVEBUTTON_H
0031 #define QTCURVEBUTTON_H
0032 
0033 #include <QImage>
0034 #include "qtcurvehandler.h"
0035 #include <kcommondecoration.h>
0036 
0037 class QTimer;
0038 class QStyle;
0039 
0040 namespace QtCurve {
0041 namespace KWin {
0042 
0043 class QtCurveClient;
0044 
0045 class QtCurveButton: public KCommonDecorationButton {
0046 public:
0047     QtCurveButton(ButtonType type, QtCurveClient *parent);
0048     ~QtCurveButton() {}
0049 
0050     void reset(unsigned long changed);
0051     QtCurveClient*
0052     client()
0053     {
0054         return m_client;
0055     }
0056 
0057 protected:
0058     void paintEvent(QPaintEvent *);
0059 
0060 private:
0061     void enterEvent(QEvent *e);
0062     void leaveEvent(QEvent *e);
0063     void drawButton(QPainter *painter);
0064     void updateMask();
0065 
0066 private:
0067     QtCurveClient *m_client;
0068     ButtonIcon m_iconType;
0069     bool m_hover;
0070 
0071     friend class IconEngine;
0072 };
0073 
0074 /**
0075  * This class creates bitmaps which can be used as icons on buttons. The icons
0076  * are "hardcoded".
0077  * Over the previous "Gimp->xpm->QImage->recolor->SmoothScale->QPixmap" solution
0078  * it has the important advantage that icons are more scalable and at the same
0079  * time sharp and not blurred.
0080  */
0081 class IconEngine {
0082 public:
0083     static QBitmap icon(ButtonIcon icon, int size, QStyle *style);
0084 
0085 private:
0086     enum Object {
0087         HorizontalLine,
0088         VerticalLine,
0089         DiagonalLine,
0090         CrossDiagonalLine
0091     };
0092 
0093     static void drawObject(QPainter &p, Object object, int x, int y,
0094                            int length, int lineWidth);
0095 };
0096 
0097 }
0098 }
0099 
0100 #endif