source: subversion/applications/editors/merkaartor/LayerWidget.cpp @ 7119

Last change on this file since 7119 was 7119, checked in by Chris Browet, 12 years ago

FIX : menu shortcuts (by streetmap) (fixes #736)
FIX : WMS tweaks + more default server (url's by ColinMarquardt?) (fixes #758)
ADD : Preferences versioning
FIX : remove tiles prefetching

File size: 6.8 KB
Line 
1#include "LayerWidget.h"
2#include "LayerDock.h"
3
4#include "MainWindow.h"
5#include "Map/MapDocument.h"
6#include "Map/MapLayer.h"
7#include "MapView.h"
8#include "Preferences/MerkaartorPreferences.h"
9
10#include <QtGui/QMouseEvent>
11#include <QtGui/QPainter>
12
13#define SAFE_DELETE(x) {delete (x); x = NULL;}
14
15#define LINEHEIGHT 25
16
17LayerWidget::LayerWidget(QWidget* aParent)
18: QAbstractButton(aParent), ctxMenu(0)
19{
20        setCheckable(true);
21        setAutoExclusive(true) ;
22        setFocusPolicy(Qt::NoFocus);
23        visibleIcon = QPixmap(":Icons/eye.xpm");
24        hiddenIcon = QPixmap(":Icons/empty.xpm");
25}
26
27QSize LayerWidget::minimumSizeHint () const
28{
29        return QSize(100, LINEHEIGHT);
30}
31
32QSize LayerWidget::sizeHint () const
33{
34        return QSize(100, LINEHEIGHT);
35}
36
37void LayerWidget::paintEvent(QPaintEvent*)
38{
39        QPainter P(this);
40
41        P.drawLine(rect().bottomLeft(), rect().bottomRight());
42        if (theLayer->isSelected()) {
43                P.fillRect(rect().adjusted(20,0,0,-1),QBrush(palette().highlight()));
44//              P.fillRect(20, 1, width()-19, rect().height()-1, QBrush(palette().highlight()));
45                P.setPen(palette().highlightedText().color());
46                P.drawText(rect().adjusted(23,0,0,-1), Qt::AlignLeft | Qt::AlignVCenter , theLayer->name());
47        } else {
48                P.fillRect(rect().adjusted(0,0,0,-1),backColor);
49                P.setPen(QColor(0,0,0));
50                P.drawText(rect().adjusted(23,0,0,-1), Qt::AlignLeft | Qt::AlignVCenter , theLayer->name());
51        }
52
53        if (theLayer->isVisible())
54                P.drawPixmap(QPoint(2, rect().center().y()-visibleIcon.height()/2), visibleIcon);
55        else
56                P.drawPixmap(QPoint(2, rect().center().y()-hiddenIcon.height()/2), hiddenIcon);
57}
58
59void LayerWidget::mouseReleaseEvent(QMouseEvent* anEvent)
60{
61        if (anEvent->pos().x()<20)
62        {
63                theLayer->setVisible(!theLayer->isVisible());
64                anEvent->ignore();
65                update();
66                emit(layerChanged(this, false));
67        }
68        else
69        {
70                if (!(dynamic_cast<ImageLayerWidget *>(this)))
71                        toggle();
72        }
73}
74
75void LayerWidget::checkStateSet()
76{
77        theLayer->setSelected(isChecked());
78        //emit (layerChanged(this));
79}
80
81MapLayer* LayerWidget::getMapLayer()
82{
83        return theLayer;
84}
85
86void LayerWidget::contextMenuEvent(QContextMenuEvent* anEvent)
87{
88        if (ctxMenu)
89                ctxMenu->exec(anEvent->globalPos());
90}
91
92
93// DrawingLayerWidget
94
95DrawingLayerWidget::DrawingLayerWidget(DrawingMapLayer* aLayer, QWidget* aParent)
96: LayerWidget(aParent)
97{
98        theLayer = aLayer;
99        backColor = QColor(255,255,255);
100}
101
102// ImageLayerWidget
103
104ImageLayerWidget::ImageLayerWidget(ImageMapLayer* aLayer, QWidget* aParent)
105: LayerWidget(aParent), actgrWms(0)
106{
107        theLayer = aLayer;
108        backColor = QColor(128,128,128);
109        //actgrAdapter = new QActionGroup(this);
110
111        actNone = new QAction(MerkaartorPreferences::instance()->getBgTypes()[Bg_None], this);
112        //actNone->setCheckable(true);
113        actNone->setChecked((MerkaartorPreferences::instance()->getBgType() == Bg_None));
114        connect(actNone, SIGNAL(triggered(bool)), this, SLOT(setNone(bool)));
115
116        actOSM = new QAction(MerkaartorPreferences::instance()->getBgTypes()[Bg_OSM], this);
117        //actNone->setCheckable(true);
118        actOSM->setChecked((MerkaartorPreferences::instance()->getBgType() == Bg_OSM));
119        connect(actOSM, SIGNAL(triggered(bool)), this, SLOT(setOSM(bool)));
120
121#ifdef yahoo_illegal
122        actYahoo = new QAction(MerkaartorPreferences::instance()->getBgTypes()[Bg_Yahoo_illegal], this);
123        //actYahoo->setCheckable(true);
124        actYahoo->setChecked((MerkaartorPreferences::instance()->getBgType() == Bg_Yahoo_illegal));
125        connect(actYahoo, SIGNAL(triggered(bool)), this, SLOT(setYahoo(bool)));
126#endif
127#ifdef google_illegal
128        actGoogle = new QAction(MerkaartorPreferences::instance()->getBgTypes()[Bg_Google_illegal], this);
129        //actGoogle->setCheckable(true);
130        actGoogle->setChecked((MerkaartorPreferences::instance()->getBgType() == Bg_Google_illegal));
131        connect(actGoogle, SIGNAL(triggered(bool)), this, SLOT(setGoogle(bool)));
132#endif
133        initWmsActions();
134}
135
136ImageLayerWidget::~ImageLayerWidget()
137{
138}
139
140void ImageLayerWidget::setWms(QAction* act)
141{
142        WmsServerList* L = MerkaartorPreferences::instance()->getWmsServers();
143        WmsServer S = L->value(act->data().toString());
144        MerkaartorPreferences::instance()->setSelectedWmsServer(S.WmsName);
145
146        ((ImageMapLayer *)theLayer)->setMapAdapter(Bg_Wms);
147        theLayer->setVisible(true);
148
149        this->update(rect());
150        emit (layerChanged(this, true));
151}
152
153#ifdef yahoo_illegal
154void ImageLayerWidget::setYahoo(bool)
155{
156        ((ImageMapLayer *)theLayer)->setMapAdapter(Bg_Yahoo_illegal);
157        theLayer->setVisible(true);
158
159        this->update(rect());
160        emit (layerChanged(this, true));
161}
162#endif
163
164#ifdef google_illegal
165void ImageLayerWidget::setGoogle(bool)
166{
167        ((ImageMapLayer *)theLayer)->setMapAdapter(Bg_Google_illegal);
168        theLayer->setVisible(true);
169
170        this->update(rect());
171        emit (layerChanged(this, true));
172}
173#endif
174
175void ImageLayerWidget::setNone(bool)
176{
177        ((ImageMapLayer *)theLayer)->setMapAdapter(Bg_None);
178
179        this->update(rect());
180        emit (layerChanged(this, true));
181}
182
183void ImageLayerWidget::setOSM(bool)
184{
185        ((ImageMapLayer *)theLayer)->setMapAdapter(Bg_OSM);
186        theLayer->setVisible(true);
187
188        this->update(rect());
189        emit (layerChanged(this, true));
190}
191
192void ImageLayerWidget::initWmsActions()
193{
194        //if (actgrWms)
195        //      delete actgrWms;
196        //actgrWms = new QActionGroup(this);
197
198        SAFE_DELETE(ctxMenu);
199
200        wmsMenu = new QMenu(MerkaartorPreferences::instance()->getBgTypes()[Bg_Wms], this);
201
202        WmsServerList* Servers = MerkaartorPreferences::instance()->getWmsServers();
203        WmsServerListIterator i(*Servers);
204        while (i.hasNext()) {
205                i.next();
206                WmsServer S = i.value();
207                QAction* act = new QAction(S.WmsName, wmsMenu);
208                act->setData(S.WmsName);
209                //act->setCheckable(true);
210                wmsMenu->addAction(act);
211                //actgrAdapter->addAction(act);
212                //actgrWms->addAction(act);
213                if (MerkaartorPreferences::instance()->getBgType() == Bg_Wms)
214                        if (S.WmsName == MerkaartorPreferences::instance()->getSelectedWmsServer())
215                                act->setChecked(true);
216        }
217        actNone->setChecked((MerkaartorPreferences::instance()->getBgType() == Bg_None));
218#ifdef yahoo_illegal
219        actYahoo->setChecked((MerkaartorPreferences::instance()->getBgType() == Bg_Yahoo_illegal));
220#endif
221#ifdef google_illegal
222        actGoogle->setChecked((MerkaartorPreferences::instance()->getBgType() == Bg_Google_illegal));
223#endif
224
225        ctxMenu = new QMenu(this);
226        ctxMenu->addAction(actNone);
227
228        ctxMenu->addMenu(wmsMenu);
229        connect(wmsMenu, SIGNAL(triggered(QAction*)), this, SLOT(setWms(QAction*)));
230
231        ctxMenu->addAction(actOSM);
232#ifdef yahoo_illegal
233        ctxMenu->addAction(actYahoo);
234#endif
235#ifdef google_illegal
236        ctxMenu->addAction(actGoogle);
237#endif
238}
239
240// TrackLayerWidget
241
242TrackLayerWidget::TrackLayerWidget(TrackMapLayer* aLayer, QWidget* /* aParent */)
243{
244        theLayer = aLayer;
245        backColor = QColor(255,255,255);
246
247        ctxMenu = new QMenu(this);
248
249        QAction* actExtract = new QAction("Extract Drawing layer", ctxMenu);
250        ctxMenu->addAction(actExtract);
251        connect(actExtract, SIGNAL(triggered(bool)), this, SLOT(extractLayer(bool)));
252}
253
254TrackLayerWidget::~TrackLayerWidget()
255{
256}
257
258void TrackLayerWidget::extractLayer(bool)
259{
260        ((TrackMapLayer*)theLayer)->extractLayer();
261        emit (layerChanged(this, false));
262}
Note: See TracBrowser for help on using the repository browser.