summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-02-24 14:43:53 (GMT)
committerTobias Markmann <tm@ayena.de>2017-02-24 14:58:12 (GMT)
commitd8b09bc1eacdf97366058807cc021f81be171526 (patch)
treee9d09ce146fd6da7f934590a6356a25c6473bf6e /Swift/QtUI/QtEmojiCell.cpp
parentec9643bb6ebd8da74864969a16bffc7fa76431c4 (diff)
downloadswift-d8b09bc1eacdf97366058807cc021f81be171526.zip
swift-d8b09bc1eacdf97366058807cc021f81be171526.tar.bz2
Use FlowLayout instead of QGridLayout in QtEmojiGrid
FlowLayout is an official BSD-licensed Qt example showing how to implement custom layouts. It will layout items dynamically in rows. This way we don’t need static column/row calculations for QGridLayout and it looks better. Test-Information: Build and ran on macOS 10.12.3 with Qt 5.7 to test that it has a better, less spacious look. Change-Id: Ief1299b0d3fb1e516a1973469f4f9a26824942f2
Diffstat (limited to 'Swift/QtUI/QtEmojiCell.cpp')
-rw-r--r--Swift/QtUI/QtEmojiCell.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/Swift/QtUI/QtEmojiCell.cpp b/Swift/QtUI/QtEmojiCell.cpp
index 4932ece..3f2c652 100644
--- a/Swift/QtUI/QtEmojiCell.cpp
+++ b/Swift/QtUI/QtEmojiCell.cpp
@@ -1,41 +1,43 @@
/*
* Copyright (c) 2016-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtEmojiCell.h>
#include <QFont>
#include <QFontMetrics>
#include <QPushButton>
#include <QString>
#include <SwifTools/EmojiMapper.h>
namespace Swift {
QtEmojiCell::QtEmojiCell(QString shortname, QString text, QWidget* parent) : QPushButton(parent) {
setText(text);
QFont font = this->font();
font.setPointSize(22);
font.setBold(true);
setFont(font);
- setFixedWidth(fontMetrics().width("\xF0\x9F\x98\x83")+5);
+ const auto boundingRect = fontMetrics().boundingRect("\xF0\x9F\x98\x83");
+ setFixedWidth(qMax(boundingRect.width(), boundingRect.height()));
+ setFixedHeight(qMax(boundingRect.width(), boundingRect.height()));
setFlat(true);
setToolTip(shortname);
connect(this, SIGNAL(clicked()), this, SLOT(handleEmojiClicked()));
}
QtEmojiCell::QtEmojiCell(const QtEmojiCell& b) : QtEmojiCell(b.toolTip(), b.text()) {
}
QtEmojiCell::~QtEmojiCell() {
}
void QtEmojiCell::handleEmojiClicked () {
emit emojiClicked(text());
}
}