File indexing completed on 2024-05-05 04:49:25

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2009 Seb Ruiz <ruiz@kde.org>                                           *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017  
0018 #ifndef ELIDINGBUTTON_H
0019 #define ELIDINGBUTTON_H
0020 
0021 #include <QPushButton>
0022 #include <QResizeEvent>
0023 #include <QSize>
0024 #include <QSizePolicy>
0025 
0026 namespace Amarok
0027 {
0028     /**
0029      * This is a reimplementaiton of a QPushButton that elides text if stretched below
0030      * its optimal width. The icon (if any) will always remain visible.
0031      */
0032     class ElidingButton : public QPushButton
0033     {
0034         Q_OBJECT
0035 
0036         public:
0037             explicit ElidingButton( QWidget *parent );
0038             ElidingButton( const QString & text, QWidget *parent );
0039             ElidingButton( const QIcon & icon, const QString & text, QWidget *parent );
0040             ~ElidingButton() override;
0041 
0042             bool isElided() const;
0043             QSizePolicy sizePolicy() const;
0044 
0045             virtual void setText( const QString &text );
0046             void resizeEvent( QResizeEvent *event ) override;
0047 
0048         Q_SIGNALS:
0049             void sizePolicyChanged();
0050 
0051         private:
0052             void init();
0053             void elideText( const QSize &widgetSize );
0054 
0055             QString m_fullText;
0056             bool m_isElided;
0057     };
0058 }
0059 
0060 #endif