38
38
#include " qgscontexthelp.h"
39
39
#include " qgscursors.h"
40
40
41
+ #include < QCloseEvent>
41
42
#include < QDesktopWidget>
42
43
#include < QFileDialog>
43
44
#include < QFileInfo>
44
45
#include < QMatrix>
46
+ #include < QMenuBar>
45
47
#include < QMessageBox>
46
48
#include < QPainter>
47
49
@@ -68,18 +70,40 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()
68
70
69
71
QString myIconPath = QgsApplication::activeThemePath ();
70
72
71
- QAction* moveItemContentAction = new QAction ( QIcon ( QPixmap ( myIconPath + " mActionMoveItemContent.png" ) ), tr ( " Move Item content" ), 0 );
73
+ // Actions defined in qgscomposerbase.ui:
74
+ // mActionAddNewMap
75
+ // mActionAddNewLegend
76
+ // mActionAddNewLabel
77
+ // mActionAddNewScalebar
78
+ // mActionAddImage
79
+ // mActionSelectMoveItem
80
+
81
+ QAction* moveItemContentAction = new QAction ( QIcon ( QPixmap ( myIconPath + " mActionMoveItemContent.png" ) ),
82
+ tr ( " Move Content" ), 0 );
83
+ moveItemContentAction->setToolTip ( tr ( " Move item content" ) );
72
84
moveItemContentAction->setCheckable ( true );
73
85
connect ( moveItemContentAction, SIGNAL ( triggered () ), this , SLOT ( moveItemContent () ) );
74
86
toolBar->addAction ( moveItemContentAction );
75
87
// toolBar->addAction(QIcon(QPixmap(myIconPath+"mActionMoveItemContent.png")), tr("Move Item content"), this, SLOT(moveItemContent()));
76
88
77
- toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionGroupItems.png" ) ), tr ( " &Group Items" ), this , SLOT ( groupItems () ) );
78
- toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionUngroupItems.png" ) ), tr ( " &Ungroup Items" ), this , SLOT ( ungroupItems () ) );
79
- toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionRaiseItems.png" ) ), tr ( " Raise selected items" ), this , SLOT ( raiseSelectedItems () ) );
80
- toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionLowerItems.png" ) ), tr ( " Lower selected items" ), this , SLOT ( lowerSelectedItems () ) );
81
- toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionMoveItemsToTop.png" ) ), tr ( " Move selected items to top" ), this , SLOT ( moveSelectedItemsToTop () ) );
82
- toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionMoveItemsToBottom.png" ) ), tr ( " Move selected items to bottom" ), this , SLOT ( moveSelectedItemsToBottom () ) );
89
+ QAction* groupItemsAction = toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionGroupItems.png" ) ),
90
+ tr ( " &Group" ), this , SLOT ( groupItems () ) );
91
+ groupItemsAction->setToolTip ( tr ( " Group items" ) );
92
+ QAction* ungroupItemsAction = toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionUngroupItems.png" ) ),
93
+ tr ( " &Ungroup" ), this , SLOT ( ungroupItems () ) );
94
+ ungroupItemsAction->setToolTip ( tr ( " Ungroup items" ) );
95
+ QAction* raiseItemsAction = toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionRaiseItems.png" ) ),
96
+ tr ( " Raise" ), this , SLOT ( raiseSelectedItems () ) );
97
+ raiseItemsAction->setToolTip ( tr ( " Raise selected items" ) );
98
+ QAction* lowerItemsAction = toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionLowerItems.png" ) ),
99
+ tr ( " Lower" ), this , SLOT ( lowerSelectedItems () ) );
100
+ lowerItemsAction->setToolTip ( tr ( " Lower selected items" ) );
101
+ QAction* moveItemsToTopAction = toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionMoveItemsToTop.png" ) ),
102
+ tr ( " Bring to Front" ), this , SLOT ( moveSelectedItemsToTop () ) );
103
+ moveItemsToTopAction->setToolTip ( tr ( " Move selected items to top" ) );
104
+ QAction* moveItemsToBottomAction = toolBar->addAction ( QIcon ( QPixmap ( myIconPath + " mActionMoveItemsToBottom.png" ) ),
105
+ tr ( " Send to Back" ), this , SLOT ( moveSelectedItemsToBottom () ) );
106
+ moveItemsToBottomAction->setToolTip ( tr ( " Move selected items to bottom" ) );
83
107
84
108
QActionGroup* toggleActionGroup = new QActionGroup ( this );
85
109
toggleActionGroup->addAction ( moveItemContentAction );
@@ -105,6 +129,68 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()
105
129
mActionAddNewScalebar ->setCheckable ( true );
106
130
mActionAddImage ->setCheckable ( true );
107
131
132
+ #ifdef Q_WS_MAC
133
+ QMenu *appMenu = menuBar ()->addMenu ( tr ( " QGIS" ) );
134
+ appMenu->addAction ( QgisApp::instance ()->actionAbout () );
135
+ appMenu->addAction ( QgisApp::instance ()->actionOptions () );
136
+
137
+ QMenu *fileMenu = menuBar ()->addMenu ( tr ( " File" ) );
138
+ fileMenu->addAction ( mActionOpenTemplate );
139
+ fileMenu->addSeparator ();
140
+ QAction *closeAction = fileMenu->addAction ( tr ( " Close" ), this , SLOT ( close () ), tr ( " Ctrl+W" ) );
141
+ fileMenu->addAction ( mActionSaveTemplateAs );
142
+ fileMenu->addAction ( mActionExportAsImage );
143
+ fileMenu->addAction ( mActionExportAsSVG );
144
+ fileMenu->addSeparator ();
145
+ fileMenu->addAction ( mActionPrint );
146
+
147
+ QMenu *editMenu = menuBar ()->addMenu ( tr ( " Edit" ) );
148
+ QAction *undoAction = editMenu->addAction ( tr ( " &Undo" ), this , SLOT ( undo () ), tr ( " Ctrl+Z" ) );
149
+ undoAction->setEnabled ( false );
150
+ editMenu->addSeparator ();
151
+ QAction *cutAction = editMenu->addAction ( tr ( " Cu&t" ), this , SLOT ( cut () ), tr ( " Ctrl+X" ) );
152
+ cutAction->setEnabled ( false );
153
+ QAction *copyAction = editMenu->addAction ( tr ( " &Copy" ), this , SLOT ( copy () ), tr ( " Ctrl+C" ) );
154
+ copyAction->setEnabled ( false );
155
+ QAction *pasteAction = editMenu->addAction ( tr ( " &Paste" ), this , SLOT ( paste () ), tr ( " Ctrl+V" ) );
156
+ pasteAction->setEnabled ( false );
157
+ QAction *deleteAction = editMenu->addAction ( tr ( " Delete" ) );
158
+ deleteAction->setEnabled ( false );
159
+
160
+ QMenu *viewMenu = menuBar ()->addMenu ( tr ( " View" ) );
161
+ viewMenu->addAction ( mActionZoomIn );
162
+ viewMenu->addAction ( mActionZoomOut );
163
+ viewMenu->addAction ( mActionZoomAll );
164
+ viewMenu->addSeparator ();
165
+ viewMenu->addAction ( mActionRefreshView );
166
+
167
+ QMenu *layoutMenu = menuBar ()->addMenu ( tr ( " Layout" ) );
168
+ layoutMenu->addAction ( mActionAddNewMap );
169
+ layoutMenu->addAction ( mActionAddNewLabel );
170
+ layoutMenu->addAction ( mActionAddNewScalebar );
171
+ layoutMenu->addAction ( mActionAddNewLegend );
172
+ layoutMenu->addAction ( mActionAddImage );
173
+ layoutMenu->addAction ( mActionSelectMoveItem );
174
+ layoutMenu->addAction ( moveItemContentAction );
175
+ layoutMenu->addSeparator ();
176
+ layoutMenu->addAction ( groupItemsAction );
177
+ layoutMenu->addAction ( ungroupItemsAction );
178
+ layoutMenu->addAction ( raiseItemsAction );
179
+ layoutMenu->addAction ( lowerItemsAction );
180
+ layoutMenu->addAction ( moveItemsToTopAction );
181
+ layoutMenu->addAction ( moveItemsToBottomAction );
182
+
183
+ #ifndef Q_WS_MAC64 /* assertion failure in NSMenuItem setSubmenu (Qt 4.5.0-snapshot-20080830) */
184
+ menuBar ()->addMenu ( QgisApp::instance ()->windowMenu () );
185
+
186
+ menuBar ()->addMenu ( QgisApp::instance ()->helpMenu () );
187
+ #endif
188
+
189
+ // Create action to select this window and add it to Window menu
190
+ mWindowAction = new QAction ( windowTitle (), this );
191
+ connect ( mWindowAction , SIGNAL ( triggered () ), this , SLOT ( activate () ) );
192
+ #endif
193
+
108
194
mQgis = qgis;
109
195
mFirstTime = true ;
110
196
@@ -208,10 +294,55 @@ void QgsComposer::open( void )
208
294
{
209
295
show (); // make sure the window is displayed - with a saved project, it's possible to not have already called show()
210
296
// is that a bug?
211
- raise (); // bring the composer window to the front
297
+ activate (); // bring the composer window to the front
212
298
}
213
299
}
214
300
301
+ void QgsComposer::activate ()
302
+ {
303
+ raise ();
304
+ setWindowState ( windowState () & ~Qt::WindowMinimized );
305
+ activateWindow ();
306
+ }
307
+
308
+ #ifdef Q_WS_MAC
309
+ void QgsComposer::changeEvent ( QEvent* event )
310
+ {
311
+ QMainWindow::changeEvent ( event );
312
+ switch ( event->type () )
313
+ {
314
+ case QEvent::ActivationChange:
315
+ if ( QApplication::activeWindow () == this )
316
+ {
317
+ mWindowAction ->setChecked ( true );
318
+ }
319
+ break ;
320
+
321
+ default :
322
+ break ;
323
+ }
324
+ }
325
+
326
+ void QgsComposer::closeEvent ( QCloseEvent *event )
327
+ {
328
+ QMainWindow::closeEvent ( event );
329
+ if ( event->isAccepted () )
330
+ {
331
+ QgisApp::instance ()->removeWindow ( mWindowAction );
332
+ }
333
+ }
334
+
335
+ void QgsComposer::showEvent ( QShowEvent *event )
336
+ {
337
+ QMainWindow::showEvent ( event );
338
+ // add to menu if (re)opening window (event not due to unminimize)
339
+ if ( !event->spontaneous () )
340
+ {
341
+ QgisApp::instance ()->addWindow ( mWindowAction );
342
+ }
343
+ }
344
+ #endif
345
+
215
346
void QgsComposer::showCompositionOptions ( QWidget *w )
216
347
{
217
348
QWidget* currentWidget = mItemStackedWidget ->currentWidget ();
0 commit comments