source: subversion/applications/editors/merkaartor/StyleDock.cpp @ 13736

Last change on this file since 13736 was 13686, checked in by Chris Browet, 11 years ago

ADD : Styles dock + list of styles in "Tools-Styles" for quick style switching. As a consequence, a directory must be defined in the preferences where all custom styles will be stored.

File size: 2.3 KB
Line 
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 "Map/MapDocument.h"
17#include "Map/MapFeature.h"
18#include "PaintStyle/EditPaintStyle.h"
19
20#include <QAction>
21
22StyleDock::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
37StyleDock::~StyleDock()
38{
39}
40
41void StyleDock::clearItems()
42{
43        ui.StyleList->blockSignals(true);
44        ui.StyleList->clear();
45        ui.StyleList->blockSignals(false);
46}
47
48void 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
61void 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
75void 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
82void StyleDock::on_StyleList_itemDoubleClicked(QListWidgetItem* item)
83{
84        Q_UNUSED(item)
85}
86
87void StyleDock::on_StyleList_customContextMenuRequested(const QPoint & pos)
88{
89        Q_UNUSED(pos)
90}
91
92void StyleDock::changeEvent(QEvent * event)
93{
94    if (event->type() == QEvent::LanguageChange)
95        retranslateUi();
96    MDockAncestor::changeEvent(event);
97}
98
99void StyleDock::retranslateUi()
100{
101    setWindowTitle(tr("Styles"));
102}
103
Note: See TracBrowser for help on using the repository browser.