diff options
author | Tobias Markmann <tm@ayena.de> | 2017-02-24 14:43:53 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2017-02-24 14:58:12 (GMT) |
commit | d8b09bc1eacdf97366058807cc021f81be171526 (patch) | |
tree | e9d09ce146fd6da7f934590a6356a25c6473bf6e /Swift/QtUI/QtEmojisGrid.cpp | |
parent | ec9643bb6ebd8da74864969a16bffc7fa76431c4 (diff) | |
download | swift-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/QtEmojisGrid.cpp')
-rw-r--r-- | Swift/QtUI/QtEmojisGrid.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/Swift/QtUI/QtEmojisGrid.cpp b/Swift/QtUI/QtEmojisGrid.cpp index eadc64f..6064a66 100644 --- a/Swift/QtUI/QtEmojisGrid.cpp +++ b/Swift/QtUI/QtEmojisGrid.cpp @@ -18,11 +18,13 @@ #include <Swift/QtUI/QtSwiftUtil.h> namespace Swift { -QtEmojisGrid::QtEmojisGrid() { + static const int emojiCellSpacing = 2; -} + QtEmojisGrid::QtEmojisGrid() : FlowLayout(0, emojiCellSpacing, emojiCellSpacing) { + + } -QtEmojisGrid::QtEmojisGrid(QString categoryName) { + QtEmojisGrid::QtEmojisGrid(QString categoryName) : FlowLayout(0, emojiCellSpacing, emojiCellSpacing) { auto category = EmojiMapper::categoryNameToEmojis(Q2PSTRING(categoryName)); QVector<QString> categoryEmojis; @@ -37,29 +39,17 @@ QtEmojisGrid::QtEmojisGrid(QString categoryName) { void QtEmojisGrid::setEmojis(const QVector<QString>& emojis) { clearEmojis(); - int iEmoji = 0; for (const auto& unicodeEmoji : emojis) { QString shortname = QString::fromStdString(EmojiMapper::unicodeToShortname(Q2PSTRING(unicodeEmoji))); - QtEmojiCell* emoji = new QtEmojiCell(shortname, unicodeEmoji); - this->addWidget(emoji, iEmoji/6, iEmoji%6); + auto emoji = new QtEmojiCell(shortname, unicodeEmoji); connect(emoji, SIGNAL(emojiClicked(QString)), this, SIGNAL(onEmojiSelected(QString))); - iEmoji++; - } - for (int index = 0; index < columnCount(); index++) { - auto layoutItem = itemAtPosition(0, index); - if (layoutItem) { - auto cellWidget = layoutItem->widget(); - if (cellWidget) { - setColumnMinimumWidth(index, cellWidget->width()); - } - } + addItem(new QWidgetItem(emoji)); } - setSpacing(5); } void QtEmojisGrid::clearEmojis() { QLayoutItem* child = nullptr; - while ((child = this->takeAt(0)) != 0) { + while ((child = this->takeAt(0)) != nullptr) { if (child->widget()) { child->widget()->hide(); removeWidget(child->widget()); |