mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 00:49:41 -05:00
Added new class StyledElidedLabel and used it for nick name and channel label.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7757 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2036f379de
commit
78c71ab011
@ -183,7 +183,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="3">
|
||||
<widget class="StyledLabel" name="nicknameLabel">
|
||||
<widget class="StyledElidedLabel" name="nicknameLabel">
|
||||
<property name="text">
|
||||
<string notr="true">Nickname (Location)</string>
|
||||
</property>
|
||||
@ -830,6 +830,11 @@
|
||||
<header location="global">gui/chat/ChatTabWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>StyledElidedLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>gui/common/StyledElidedLabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="images.qrc"/>
|
||||
|
@ -47,23 +47,28 @@
|
||||
|
||||
ElidedLabel::ElidedLabel(const QString &text, QWidget *parent)
|
||||
: QLabel(parent)
|
||||
, elided(false)
|
||||
, content(text)
|
||||
, mElided(false)
|
||||
, mContent(text)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
ElidedLabel::ElidedLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
, elided(false)
|
||||
, mElided(false)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
content="";
|
||||
}
|
||||
|
||||
void ElidedLabel::setText(const QString &newText)
|
||||
{
|
||||
content = newText;
|
||||
mContent = newText;
|
||||
update();
|
||||
}
|
||||
|
||||
void ElidedLabel::clear()
|
||||
{
|
||||
mContent.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
@ -80,7 +85,7 @@ void ElidedLabel::paintEvent(QPaintEvent *event)
|
||||
int lineSpacing = fontMetrics.lineSpacing();
|
||||
int x, y = x =cr.top()+(cr.height()-lineSpacing)/2;
|
||||
|
||||
QTextLayout textLayout( content, painter.font());
|
||||
QTextLayout textLayout(mContent, painter.font());
|
||||
textLayout.beginLayout();
|
||||
forever {
|
||||
QTextLine line = textLayout.createLine();
|
||||
@ -95,7 +100,7 @@ void ElidedLabel::paintEvent(QPaintEvent *event)
|
||||
line.draw(&painter, QPoint(x, y));
|
||||
y = nextLineY;
|
||||
} else {
|
||||
QString lastLine = content.mid(line.textStart());
|
||||
QString lastLine = mContent.mid(line.textStart());
|
||||
QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, cr.width());
|
||||
painter.drawText(QPoint(x, y + fontMetrics.ascent()), elidedLastLine);
|
||||
line = textLayout.createLine();
|
||||
@ -105,8 +110,8 @@ void ElidedLabel::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
textLayout.endLayout();
|
||||
|
||||
if (didElide != elided) {
|
||||
elided = didElide;
|
||||
if (didElide != mElided) {
|
||||
mElided = didElide;
|
||||
emit elisionChanged(didElide);
|
||||
}
|
||||
}
|
||||
|
@ -38,38 +38,41 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef ELIDEDLABEL_H
|
||||
#define ELIDEDLABEL_H
|
||||
#ifndef ELIDEDLABEL_H
|
||||
#define ELIDEDLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QRect>
|
||||
#include <QResizeEvent>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QRect>
|
||||
#include <QResizeEvent>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
class ElidedLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(bool isElided READ isElided)
|
||||
class ElidedLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(bool isElided READ isElided)
|
||||
|
||||
public:
|
||||
ElidedLabel(const QString &text, QWidget *parent = 0);
|
||||
ElidedLabel(QWidget *parent = 0);
|
||||
public:
|
||||
ElidedLabel(const QString &text, QWidget *parent = 0);
|
||||
ElidedLabel(QWidget *parent = 0);
|
||||
|
||||
void setText(const QString &text);
|
||||
const QString & text() const { return content; }
|
||||
bool isElided() const { return elided; }
|
||||
const QString & text() const { return mContent; }
|
||||
bool isElided() const { return mElided; }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
public slots:
|
||||
void setText(const QString &text);
|
||||
void clear();
|
||||
|
||||
signals:
|
||||
void elisionChanged(bool elided);
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
bool elided;
|
||||
QString content;
|
||||
};
|
||||
signals:
|
||||
void elisionChanged(bool elided);
|
||||
|
||||
#endif // TEXTWRAPPINGWIDGET_H
|
||||
private:
|
||||
bool mElided;
|
||||
QString mContent;
|
||||
};
|
||||
|
||||
#endif // ELIDEDLABEL_H
|
||||
|
43
retroshare-gui/src/gui/common/StyledElidedLabel.cpp
Normal file
43
retroshare-gui/src/gui/common/StyledElidedLabel.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2014, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <QFont>
|
||||
|
||||
#include "StyledElidedLabel.h"
|
||||
|
||||
/** Constructor */
|
||||
StyledElidedLabel::StyledElidedLabel(QWidget *parent)
|
||||
: ElidedLabel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
StyledElidedLabel::StyledElidedLabel(const QString &text, QWidget *parent)
|
||||
: ElidedLabel(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void StyledElidedLabel::setFontSizeFactor(int factor)
|
||||
{
|
||||
QFont f = font();
|
||||
qreal fontSize = factor * f.pointSizeF() / 100;
|
||||
f.setPointSizeF(fontSize);
|
||||
setFont(f);
|
||||
}
|
39
retroshare-gui/src/gui/common/StyledElidedLabel.h
Normal file
39
retroshare-gui/src/gui/common/StyledElidedLabel.h
Normal file
@ -0,0 +1,39 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2014, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef _STYLEDELIDEDLABEL_H
|
||||
#define _STYLEDELIDEDLABEL_H
|
||||
|
||||
#include "ElidedLabel.h"
|
||||
|
||||
class StyledElidedLabel : public ElidedLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int fontSizeFactor WRITE setFontSizeFactor)
|
||||
|
||||
public:
|
||||
StyledElidedLabel(QWidget *parent = NULL);
|
||||
StyledElidedLabel(const QString &text, QWidget *parent = NULL);
|
||||
|
||||
void setFontSizeFactor(int factor);
|
||||
};
|
||||
|
||||
#endif
|
@ -29,6 +29,11 @@ StyledLabel::StyledLabel(QWidget *parent)
|
||||
{
|
||||
}
|
||||
|
||||
StyledLabel::StyledLabel(const QString &text, QWidget *parent)
|
||||
: QLabel(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void StyledLabel::setFontSizeFactor(int factor)
|
||||
{
|
||||
QFont f = font();
|
||||
|
@ -23,7 +23,6 @@
|
||||
#define _STYLEDLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
||||
class StyledLabel : public QLabel
|
||||
{
|
||||
@ -32,6 +31,7 @@ class StyledLabel : public QLabel
|
||||
|
||||
public:
|
||||
StyledLabel(QWidget *parent = NULL);
|
||||
StyledLabel(const QString &text, QWidget *parent = NULL);
|
||||
|
||||
void setFontSizeFactor(int factor);
|
||||
};
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "UIStateHelper.h"
|
||||
#include "RSTreeWidget.h"
|
||||
#include "RSTextBrowser.h"
|
||||
#include "ElidedLabel.h"
|
||||
|
||||
class UIStateHelperObject
|
||||
{
|
||||
@ -36,6 +37,11 @@ public:
|
||||
init();
|
||||
mLabel = widget;
|
||||
}
|
||||
UIStateHelperObject(ElidedLabel *widget)
|
||||
{
|
||||
init();
|
||||
mElidedLabel = widget;
|
||||
}
|
||||
UIStateHelperObject(QLineEdit *widget)
|
||||
{
|
||||
init();
|
||||
@ -58,6 +64,10 @@ public:
|
||||
mLabel->setText(text);
|
||||
}
|
||||
|
||||
if (mElidedLabel) {
|
||||
mElidedLabel->setText(text);
|
||||
}
|
||||
|
||||
if (mLineEdit) {
|
||||
if (loading && clear) {
|
||||
mLineEdit->clear();
|
||||
@ -93,6 +103,10 @@ public:
|
||||
mLabel->clear();
|
||||
}
|
||||
|
||||
if (mElidedLabel) {
|
||||
mElidedLabel->clear();
|
||||
}
|
||||
|
||||
if (mLineEdit) {
|
||||
mLineEdit->clear();
|
||||
}
|
||||
@ -112,6 +126,10 @@ public:
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
if (mElidedLabel) {
|
||||
return mElidedLabel;
|
||||
}
|
||||
|
||||
if (mLineEdit) {
|
||||
return mLineEdit;
|
||||
}
|
||||
@ -133,6 +151,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mElidedLabel == widget) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mLineEdit == widget) {
|
||||
return true;
|
||||
}
|
||||
@ -151,9 +173,10 @@ public:
|
||||
bool operator ==(const UIStateHelperObject &data) const
|
||||
{
|
||||
if (mLabel == data.mLabel &&
|
||||
mLineEdit == data.mLineEdit &&
|
||||
mTreeWidget == data.mTreeWidget &&
|
||||
mRSTextBrowser == data.mRSTextBrowser) {
|
||||
mElidedLabel == data.mElidedLabel &&
|
||||
mLineEdit == data.mLineEdit &&
|
||||
mTreeWidget == data.mTreeWidget &&
|
||||
mRSTextBrowser == data.mRSTextBrowser) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -163,9 +186,10 @@ public:
|
||||
bool operator <(const UIStateHelperObject &data) const
|
||||
{
|
||||
if (mLabel < data.mLabel ||
|
||||
mLineEdit < data.mLineEdit ||
|
||||
mTreeWidget < data.mTreeWidget ||
|
||||
mRSTextBrowser < data.mRSTextBrowser) {
|
||||
mElidedLabel < data.mElidedLabel ||
|
||||
mLineEdit < data.mLineEdit ||
|
||||
mTreeWidget < data.mTreeWidget ||
|
||||
mRSTextBrowser < data.mRSTextBrowser) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -176,6 +200,7 @@ private:
|
||||
void init()
|
||||
{
|
||||
mLabel = NULL;
|
||||
mElidedLabel = NULL;
|
||||
mLineEdit = NULL;
|
||||
mTreeWidget = NULL;
|
||||
mRSTextBrowser = NULL;
|
||||
@ -183,6 +208,7 @@ private:
|
||||
|
||||
private:
|
||||
QLabel *mLabel;
|
||||
ElidedLabel *mElidedLabel;
|
||||
QLineEdit *mLineEdit;
|
||||
RSTreeWidget *mTreeWidget;
|
||||
RSTextBrowser *mRSTextBrowser;
|
||||
@ -247,6 +273,12 @@ void UIStateHelper::addLoadPlaceholder(int index, QLabel *widget, bool clear, co
|
||||
data->mLoad.insert(UIStateHelperObject(widget), QPair<QString, bool>(text.isEmpty() ? tr("Loading") : text, clear));
|
||||
}
|
||||
|
||||
void UIStateHelper::addLoadPlaceholder(int index, ElidedLabel *widget, bool clear, const QString &text)
|
||||
{
|
||||
UIStateHelperData *data = findData(index, true);
|
||||
data->mLoad.insert(UIStateHelperObject(widget), QPair<QString, bool>(text.isEmpty() ? tr("Loading") : text, clear));
|
||||
}
|
||||
|
||||
void UIStateHelper::addLoadPlaceholder(int index, QLineEdit *widget, bool clear, const QString &text)
|
||||
{
|
||||
UIStateHelperData *data = findData(index, true);
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
class QWidget;
|
||||
class QLabel;
|
||||
class ElidedLabel;
|
||||
class QLineEdit;
|
||||
class RSTreeWidget;
|
||||
class UIStateHelperData;
|
||||
@ -59,6 +60,7 @@ public:
|
||||
/* Add widgets */
|
||||
void addWidget(int index, QWidget *widget, UIStates states = UISTATE_LOADING_DISABLED | UISTATE_ACTIVE_ENABLED);
|
||||
void addLoadPlaceholder(int index, QLabel *widget, bool clear = true, const QString &text = "" /* ="Loading" */);
|
||||
void addLoadPlaceholder(int index, ElidedLabel *widget, bool clear = true, const QString &text = "" /* ="Loading" */);
|
||||
void addLoadPlaceholder(int index, QLineEdit *widget, bool clear = true, const QString &text = "" /* ="Loading" */);
|
||||
void addLoadPlaceholder(int index, RSTreeWidget *widget, bool clear = true, const QString &text = "" /* ="Loading" */);
|
||||
void addLoadPlaceholder(int index, RSTextBrowser *widget, bool clear = true, const QString &text = "" /* ="Loading" */);
|
||||
|
@ -73,7 +73,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="StyledLabel" name="nameLabel">
|
||||
<widget class="StyledElidedLabel" name="nameLabel">
|
||||
<property name="palette">
|
||||
<palette>
|
||||
<active/>
|
||||
@ -84,9 +84,6 @@
|
||||
<property name="text">
|
||||
<string notr="true">Channel Name</string>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -306,6 +303,11 @@
|
||||
<zorder>fileWidget</zorder>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>StyledElidedLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>gui/common/StyledElidedLabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>LineEditClear</class>
|
||||
<extends>QLineEdit</extends>
|
||||
@ -328,11 +330,6 @@
|
||||
<header>gui/gxschannels/GxsChannelFilesWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>StyledLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>gui/common/StyledLabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
|
@ -480,6 +480,7 @@ HEADERS += rshare.h \
|
||||
gui/common/FlowLayout.h \
|
||||
gui/common/PictureFlow.h \
|
||||
gui/common/StyledLabel.h \
|
||||
gui/common/StyledElidedLabel.h \
|
||||
gui/style/RSStyle.h \
|
||||
gui/style/StyleDialog.h \
|
||||
gui/MessagesDialog.h \
|
||||
@ -778,6 +779,7 @@ SOURCES += main.cpp \
|
||||
gui/common/FlowLayout.cpp \
|
||||
gui/common/PictureFlow.cpp \
|
||||
gui/common/StyledLabel.cpp \
|
||||
gui/common/StyledElidedLabel.cpp \
|
||||
gui/style/RSStyle.cpp \
|
||||
gui/style/StyleDialog.cpp \
|
||||
gui/settings/rsharesettings.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user