diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-05-24 15:49:03 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-05-24 15:49:03 (GMT) |
commit | 10534d5b942e7ef1e2f8e6900fb5b17411111b06 (patch) | |
tree | dad1d97e518614150b38a4f7a1e262228b732bff /Swift | |
parent | c85da0a6e0448b07c51ae07e41a6714429510b83 (diff) | |
download | swift-10534d5b942e7ef1e2f8e6900fb5b17411111b06.zip swift-10534d5b942e7ef1e2f8e6900fb5b17411111b06.tar.bz2 |
Elide text in the roster header when it's wider than the roster.
Resolves: #369
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtElidingLabel.cpp | 37 | ||||
-rw-r--r-- | Swift/QtUI/QtElidingLabel.h | 23 | ||||
-rw-r--r-- | Swift/QtUI/QtRosterHeader.cpp | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtStatusWidget.cpp | 7 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 1 |
5 files changed, 68 insertions, 3 deletions
diff --git a/Swift/QtUI/QtElidingLabel.cpp b/Swift/QtUI/QtElidingLabel.cpp new file mode 100644 index 0000000..80da607 --- /dev/null +++ b/Swift/QtUI/QtElidingLabel.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swift/QtUI/QtElidingLabel.h" + +namespace Swift { +QtElidingLabel::QtElidingLabel(QWidget* parent, Qt::WindowFlags f) : QLabel(parent, f) { + setSizes(); +} + +QtElidingLabel::QtElidingLabel(const QString& text, QWidget* parent, Qt::WindowFlags f) : QLabel(text, parent, f) { + setSizes(); +} + +QtElidingLabel::~QtElidingLabel() { + +} + +void QtElidingLabel::setSizes() { + setMinimumSize(1, minimumHeight()); +} + +void QtElidingLabel::paintEvent(QPaintEvent* event) { + //QPainter painter(this); + QString fullText(text()); + if (fontMetrics().width(fullText) > contentsRect().width()) { + //QString elidedText(fontMetrics().elidedText(fullText)); + setText(fontMetrics().elidedText(fullText, Qt::ElideRight, rect().width(), Qt::TextShowMnemonic)); + } + QLabel::paintEvent(event); + setText(fullText); +} + +} diff --git a/Swift/QtUI/QtElidingLabel.h b/Swift/QtUI/QtElidingLabel.h new file mode 100644 index 0000000..589d6f6 --- /dev/null +++ b/Swift/QtUI/QtElidingLabel.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QLabel> + +namespace Swift { + class QtElidingLabel : public QLabel { + Q_OBJECT + public: + QtElidingLabel(QWidget* parent = NULL, Qt::WindowFlags f = 0); + QtElidingLabel(const QString &text, QWidget* parent = NULL, Qt::WindowFlags f = 0); + virtual ~QtElidingLabel(); + + virtual void paintEvent(QPaintEvent* event); + private: + void setSizes(); + }; +} diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp index 6efb80d..fc3d0e6 100644 --- a/Swift/QtUI/QtRosterHeader.cpp +++ b/Swift/QtUI/QtRosterHeader.cpp @@ -14,6 +14,7 @@ #include <QMouseEvent> #include "QtStatusWidget.h" +#include "Swift/QtUI/QtElidingLabel.h" namespace Swift { QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) { @@ -36,7 +37,7 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) { rightLayout->setContentsMargins(4,0,0,0); topLayout->addLayout(rightLayout); - nameLabel_ = new QLabel(this); + nameLabel_ = new QtElidingLabel(this); setName("Me"); rightLayout->addWidget(nameLabel_); diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp index da8b883..28df59c 100644 --- a/Swift/QtUI/QtStatusWidget.cpp +++ b/Swift/QtUI/QtStatusWidget.cpp @@ -19,6 +19,8 @@ #include <QListWidget> #include <QListWidgetItem> +#include "Swift/QtUI/QtElidingLabel.h" + namespace Swift { QtStatusWidget::QtStatusWidget(QWidget *parent) : QWidget(parent), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) { @@ -46,7 +48,7 @@ QtStatusWidget::QtStatusWidget(QWidget *parent) : QWidget(parent), editCursor_(Q statusIcon_->setMaximumSize(16, 16); page1Layout->addWidget(statusIcon_); - statusTextLabel_ = new QLabel(this); + statusTextLabel_ = new QtElidingLabel(this); page1Layout->addWidget(statusTextLabel_); icons_[StatusShow::Online] = QIcon(":/icons/online.png"); @@ -103,7 +105,8 @@ void QtStatusWidget::handleClicked() { int y = point.y(); int width = 200; int height = 80; - int screenWidth = QApplication::desktop()->screenGeometry().width(); + int desktop = QApplication::desktop()->screenNumber(this); + int screenWidth = QApplication::desktop()->screenGeometry(desktop).width(); if (x + width > screenWidth) { x = screenWidth - width; } diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 1c7f20b..d948729 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -77,6 +77,7 @@ sources = [ "ChatSnippet.cpp", "MessageSnippet.cpp", "SystemMessageSnippet.cpp", + "QtElidingLabel.cpp", "Roster/RosterModel.cpp", "Roster/QtTreeWidget.cpp", # "Roster/QtTreeWidgetItem.cpp", |