2018-12-27 10:35:21 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/common/ElidedLabel.h *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2012, Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
// Inspired from Qt examples set
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
#ifndef ELIDEDLABEL_H
|
|
|
|
#define ELIDEDLABEL_H
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QString>
|
|
|
|
#include <QWidget>
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
class ElidedLabel : public QLabel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString text READ text WRITE setText)
|
|
|
|
Q_PROPERTY(bool isElided READ isElided)
|
2015-08-29 15:06:36 -04:00
|
|
|
Q_PROPERTY(bool isOnlyPlainText READ isOnlyPlainText WRITE setOnlyPlainText)
|
2016-10-16 09:48:50 -04:00
|
|
|
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
public:
|
|
|
|
ElidedLabel(const QString &text, QWidget *parent = 0);
|
|
|
|
ElidedLabel(QWidget *parent = 0);
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
const QString & text() const { return mContent; }
|
|
|
|
bool isElided() const { return mElided; }
|
2015-08-29 15:06:36 -04:00
|
|
|
bool isOnlyPlainText() const { return mOnlyPlainText; }
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2016-10-16 09:48:50 -04:00
|
|
|
QColor textColor() const { return mTextColor; }
|
|
|
|
void setTextColor(const QColor &color);
|
|
|
|
|
2020-02-18 04:50:55 -05:00
|
|
|
static bool paintElidedLine(QPainter& painter, QString plainText, const QRect &cr, Qt::Alignment alignment, bool wordWrap, bool drawRoundRect, QRect &rectElision);
|
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
public slots:
|
|
|
|
void setText(const QString &text);
|
2015-08-29 15:06:36 -04:00
|
|
|
void setOnlyPlainText(const bool &value);
|
2014-12-14 12:05:43 -05:00
|
|
|
void clear();
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *event);
|
2015-08-29 15:06:36 -04:00
|
|
|
void mousePressEvent(QMouseEvent *ev);
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
signals:
|
|
|
|
void elisionChanged(bool elided);
|
2014-01-20 15:03:24 -05:00
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
private:
|
|
|
|
bool mElided;
|
2015-08-29 15:06:36 -04:00
|
|
|
bool mOnlyPlainText;
|
2014-12-14 12:05:43 -05:00
|
|
|
QString mContent;
|
2015-08-29 15:06:36 -04:00
|
|
|
QRect mRectElision;
|
2016-10-16 09:48:50 -04:00
|
|
|
QColor mTextColor;
|
2014-12-14 12:05:43 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ELIDEDLABEL_H
|