summaryrefslogtreecommitdiffstats
blob: 4c8c024a9dce0256cd2144c0d9dfc34918516ee1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (c) 2015 Daniel Baczynski
 * Licensed under the Simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swift/QtUI/QtEmoticonsGrid.h>

#include <set>

#include <boost/range/adaptor/reversed.hpp>

#include <QPushButton>

#include <Swift/QtUI/QtSwiftUtil.h>

namespace Swift {

QtEmoticonsGrid::QtEmoticonsGrid(const std::map<std::string, std::string>& emoticons, QWidget* parent) : QGridLayout(parent) {
    makeUniqueEmoticonsMap(emoticons);

    // Create grid: 3 columns, [uniqueEmoticons_.size()/3] rows
    int row = 0;
    int column = 0;

    for (auto&& emoticon : uniqueEmoticons_) {
        QtEmoticonCell* newCell = new QtEmoticonCell(P2QSTRING(emoticon.first), P2QSTRING(emoticon.second));
        addWidget(newCell, row, column);
        connect(newCell, SIGNAL(emoticonClicked(QString)), this, SLOT(emoticonClickedSlot(QString)));

        column++;
        if (column >= 3) {
            column = 0;
            row++;
        }
    }
}

QtEmoticonsGrid::~QtEmoticonsGrid() {

}

void QtEmoticonsGrid::makeUniqueEmoticonsMap(const std::map<std::string, std::string>& emoticons) {
    std::set<std::string> paths;
    for (auto&& emoticon : boost::adaptors::reverse(emoticons)) {
        if (paths.find(emoticon.second) == paths.end()) {
            uniqueEmoticons_.insert(emoticon);
            paths.insert(emoticon.second);
        }
    }
}

void QtEmoticonsGrid::emoticonClickedSlot(QString emoticonAsText) {
    emit emoticonClicked(emoticonAsText);
}

}