File indexing completed on 2024-05-05 04:49:30
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef TOKENWITHLAYOUT_H 0018 #define TOKENWITHLAYOUT_H 0019 0020 #include "widgets/Token.h" 0021 0022 #include <QPointer> 0023 0024 class LayoutEditDialog; 0025 0026 class Wrench : public QLabel 0027 { 0028 Q_OBJECT 0029 public: 0030 explicit Wrench( QWidget *parent ); 0031 protected: 0032 void enterEvent(QEvent *) override; 0033 void leaveEvent(QEvent *) override; 0034 void mousePressEvent( QMouseEvent *e ) override; 0035 void mouseReleaseEvent( QMouseEvent *e ) override; 0036 void paintEvent( QPaintEvent *pe ) override; 0037 Q_SIGNALS: 0038 void clicked(); 0039 }; 0040 0041 class TokenWithLayoutFactory : public TokenFactory 0042 { 0043 public: 0044 Token * createToken( const QString &text, const QString &iconName, qint64 value, QWidget *parent = nullptr ) const override; 0045 }; 0046 0047 /** 0048 An extended Token with controls for layouting the token and getting layout values for use outside the Token. 0049 0050 @author Nikolaj Hald Nielsen <nhn@kde.org> 0051 */ 0052 class TokenWithLayout : public Token 0053 { 0054 Q_OBJECT 0055 public: 0056 TokenWithLayout( const QString &text, const QString &iconName, qint64 value, QWidget *parent = nullptr ); 0057 ~TokenWithLayout() override; 0058 0059 Qt::Alignment alignment(); 0060 bool bold() const; 0061 bool italic() const; 0062 bool underline() const; 0063 inline qreal size() const { return width(); } 0064 qreal width() const; 0065 0066 /** Return true if the width is determined by width(). It's automatic otherwise */ 0067 inline bool widthForced() const { return m_width > 0.0; } 0068 0069 /** Returns the text that is added to the front of the value */ 0070 inline QString prefix() const { return m_prefix; } 0071 0072 /** Returns the text that is added to the back of the value such as "%" */ 0073 inline QString suffix() const { return m_suffix; } 0074 0075 public Q_SLOTS: 0076 void setAlignment( Qt::Alignment alignment ); 0077 void setBold( bool bold ); 0078 void setItalic( bool italic ); 0079 void setUnderline( bool underline ); 0080 void setPrefix( const QString& ); 0081 void setSuffix( const QString& ); 0082 0083 /** Set the width of the token to a percentage of the whole line. 0084 * 0085 * @param width A number from 0 to 100. A width of >0 will 0086 * automatically set "forced" to true. 0087 */ 0088 void setWidth( int width ); 0089 0090 protected: 0091 void enterEvent(QEvent *) override; 0092 bool eventFilter( QObject*, QEvent* ) override; 0093 void leaveEvent(QEvent *) override; 0094 void timerEvent( QTimerEvent* ) override; 0095 0096 private Q_SLOTS: 0097 void showConfig(); 0098 0099 private: 0100 0101 Qt::Alignment m_alignment; 0102 bool m_bold; 0103 bool m_italic; 0104 bool m_underline; 0105 qreal m_width; 0106 QString m_prefix, m_suffix; 0107 Wrench *m_wrench; 0108 int m_wrenchTimer; 0109 static QPointer<LayoutEditDialog> m_dialog; 0110 0111 }; 0112 0113 #endif