~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to src/Docks/StyleDock.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: StyleDock
 
3
//
 
4
// Description:
 
5
//
 
6
//
 
7
// Author: cbro <cbro@semperpax.com>, (C) 2009
 
8
//
 
9
// Copyright: See COPYING file that comes with this distribution
 
10
//
 
11
//
 
12
#include "StyleDock.h"
 
13
 
 
14
#include "MainWindow.h"
 
15
#include "MapView.h"
 
16
#include "Maps/MapDocument.h"
 
17
#include "Maps/MapFeature.h"
 
18
#include "PaintStyle/EditPaintStyle.h"
 
19
 
 
20
#include <QAction>
 
21
 
 
22
StyleDock::StyleDock(MainWindow* aParent)
 
23
    : MDockAncestor(aParent), Main(aParent)
 
24
{
 
25
    setMinimumSize(220,100);
 
26
    setObjectName("StyleDock");
 
27
 
 
28
    ui.setupUi(getWidget());
 
29
 
 
30
    connect(ui.StyleList, SIGNAL(itemSelectionChanged()), this, SLOT(on_StyleList_itemSelectionChanged()));
 
31
    connect(ui.StyleList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(on_StyleList_itemDoubleClicked(QListWidgetItem*)));
 
32
    connect(ui.StyleList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_StyleList_customContextMenuRequested(const QPoint &)));
 
33
 
 
34
    retranslateUi();
 
35
}
 
36
 
 
37
StyleDock::~StyleDock()
 
38
{
 
39
}
 
40
 
 
41
void StyleDock::clearItems()
 
42
{
 
43
        ui.StyleList->blockSignals(true);
 
44
        ui.StyleList->clear();
 
45
        ui.StyleList->blockSignals(false);
 
46
}
 
47
 
 
48
void StyleDock::addItem(QAction* a)
 
49
{
 
50
        ui.StyleList->blockSignals(true);
 
51
 
 
52
        QListWidgetItem* it = new QListWidgetItem(a->text());
 
53
        it->setData(Qt::UserRole, qVariantFromValue((void *)a));
 
54
    ui.StyleList->addItem(it);
 
55
        if (a->data().toString() == M_PREFS->getDefaultStyle())
 
56
                ui.StyleList->setCurrentItem(it);
 
57
 
 
58
        ui.StyleList->blockSignals(false);
 
59
}
 
60
 
 
61
void StyleDock::setCurrent(QAction* a)
 
62
{
 
63
        ui.StyleList->blockSignals(true);
 
64
 
 
65
        for (int i=0; i < ui.StyleList->count(); i++) {
 
66
                if (ui.StyleList->item(i)->data(Qt::UserRole).value<void *>() == a) {
 
67
                        ui.StyleList->setCurrentRow(i);
 
68
                        break;
 
69
                }
 
70
        }
 
71
 
 
72
        ui.StyleList->blockSignals(false);
 
73
}
 
74
 
 
75
void StyleDock::on_StyleList_itemSelectionChanged()
 
76
{
 
77
        QListWidgetItem* item = ui.StyleList->currentItem();
 
78
        QAction * a = (QAction *)item->data(Qt::UserRole).value<void *>();
 
79
        a->trigger();
 
80
}
 
81
 
 
82
void StyleDock::on_StyleList_itemDoubleClicked(QListWidgetItem* item)
 
83
{
 
84
        Q_UNUSED(item)
 
85
}
 
86
 
 
87
void StyleDock::on_StyleList_customContextMenuRequested(const QPoint & pos)
 
88
{
 
89
        Q_UNUSED(pos)
 
90
}
 
91
 
 
92
void StyleDock::changeEvent(QEvent * event)
 
93
{
 
94
    if (event->type() == QEvent::LanguageChange)
 
95
        retranslateUi();
 
96
    MDockAncestor::changeEvent(event);
 
97
}
 
98
 
 
99
void StyleDock::retranslateUi()
 
100
{
 
101
    setWindowTitle(tr("Styles"));
 
102
}
 
103