Skip to content

Commit c6774f8

Browse files
author
telwertowski
committedAug 31, 2008
Add Mac menubars for PrintComposer and AttributeTable windows.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9223 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

8 files changed

+340
-43
lines changed

8 files changed

+340
-43
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 139 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
#include "qgscontexthelp.h"
3939
#include "qgscursors.h"
4040

41+
#include <QCloseEvent>
4142
#include <QDesktopWidget>
4243
#include <QFileDialog>
4344
#include <QFileInfo>
4445
#include <QMatrix>
46+
#include <QMenuBar>
4547
#include <QMessageBox>
4648
#include <QPainter>
4749

@@ -68,18 +70,40 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()
6870

6971
QString myIconPath = QgsApplication::activeThemePath();
7072

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" ) );
7284
moveItemContentAction->setCheckable( true );
7385
connect( moveItemContentAction, SIGNAL( triggered() ), this, SLOT( moveItemContent() ) );
7486
toolBar->addAction( moveItemContentAction );
7587
//toolBar->addAction(QIcon(QPixmap(myIconPath+"mActionMoveItemContent.png")), tr("Move Item content"), this, SLOT(moveItemContent()));
7688

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" ) );
83107

84108
QActionGroup* toggleActionGroup = new QActionGroup( this );
85109
toggleActionGroup->addAction( moveItemContentAction );
@@ -105,6 +129,68 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()
105129
mActionAddNewScalebar->setCheckable( true );
106130
mActionAddImage->setCheckable( true );
107131

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+
108194
mQgis = qgis;
109195
mFirstTime = true;
110196

@@ -208,10 +294,55 @@ void QgsComposer::open( void )
208294
{
209295
show(); //make sure the window is displayed - with a saved project, it's possible to not have already called show()
210296
//is that a bug?
211-
raise(); //bring the composer window to the front
297+
activate(); //bring the composer window to the front
212298
}
213299
}
214300

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+
215346
void QgsComposer::showCompositionOptions( QWidget *w )
216347
{
217348
QWidget* currentWidget = mItemStackedWidget->currentWidget();

‎src/app/composer/qgscomposer.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,23 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
9292
//! Restore the window and toolbar state
9393
void restoreWindowState();
9494

95+
protected:
9596
//! Move event
96-
void moveEvent( QMoveEvent * );
97+
virtual void moveEvent( QMoveEvent * );
9798

9899
//! Resize event
99-
void resizeEvent( QResizeEvent * );
100+
virtual void resizeEvent( QResizeEvent * );
101+
102+
#ifdef Q_WS_MAC
103+
//! Change event (update window menu on ActivationChange)
104+
virtual void changeEvent( QEvent * );
105+
106+
//! Close event (remove window from menu)
107+
virtual void closeEvent( QCloseEvent * );
108+
109+
//! Show event (add window to menu)
110+
virtual void showEvent( QShowEvent * );
111+
#endif
100112

101113
public slots:
102114
//! Zoom to full extent of the paper
@@ -205,11 +217,15 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
205217

206218
void setSelectionTool();
207219

220+
private slots:
221+
222+
//! Raise, unminimize and activate this window
223+
void activate();
208224

209225
private:
210-
//! Set teh pixmap / icons on the toolbar buttons
226+
//! Set the pixmap / icons on the toolbar buttons
211227
void setupTheme();
212-
/**Etablishes the signal slot connection for the class*/
228+
/**Establishes the signal slot connection for the class*/
213229
void connectSlots();
214230

215231
//! Set buttons up
@@ -245,6 +261,11 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
245261
//! To know which item to show if selection changes
246262
QMap<QgsComposerItem*, QWidget*> mItemWidgetMap;
247263

264+
#ifdef Q_WS_MAC
265+
//! Window menu action to select this window
266+
QAction *mWindowAction;
267+
#endif
268+
248269
//! Help context id
249270
static const int context_id = 985715179;
250271

‎src/app/qgisapp.cpp

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
368368
#ifdef Q_WS_MAC
369369
// action for Window menu (create before generating WindowTitleChange event))
370370
mWindowAction = new QAction( this );
371-
mWindowAction->setCheckable( true );
372371
connect( mWindowAction, SIGNAL( triggered() ), this, SLOT( activate() ) );
373372

374373
// add this window to Window menu
@@ -571,6 +570,7 @@ void QgisApp::createActions()
571570
mActionExit = new QAction( getThemeIcon( "mActionFileExit.png" ), tr( "Exit" ), this );
572571
mActionExit->setShortcut( tr( "Ctrl+Q", "Exit QGIS" ) );
573572
mActionExit->setStatusTip( tr( "Exit QGIS" ) );
573+
mActionExit->setMenuRole( QAction::QuitRole ); // put in Application menu on Mac OS X
574574
connect( mActionExit, SIGNAL( triggered() ), this, SLOT( fileExit() ) );
575575

576576
// Edit Menu Items
@@ -870,14 +870,13 @@ void QgisApp::createActions()
870870
mActionOptions = new QAction( getThemeIcon( "mActionOptions.png" ), tr( "Options..." ), this );
871871
// mActionOptions->setShortcut(tr("Alt+O","Change various QGIS options"));
872872
mActionOptions->setStatusTip( tr( "Change various QGIS options" ) );
873-
mActionOptions->setMenuRole( QAction::PreferencesRole );
873+
mActionOptions->setMenuRole( QAction::PreferencesRole ); // put in application menu on Mac OS X
874874
connect( mActionOptions, SIGNAL( triggered() ), this, SLOT( options() ) );
875875

876876
mActionCustomProjection = new QAction( getThemeIcon( "mActionCustomProjection.png" ), tr( "Custom CRS..." ), this );
877877
// mActionCustomProjection->setShortcut(tr("Alt+I","Manage custom projections"));
878878
mActionCustomProjection->setStatusTip( tr( "Manage custom coordinate reference systems" ) );
879-
// mActionCustomProjection->setMenuRole(QAction::ApplicationSpecificRole);
880-
mActionCustomProjection->setMenuRole( QAction::PreferencesRole );
879+
// mActionCustomProjection->setMenuRole( QAction::ApplicationSpecificRole ); // put in application menu on Mac OS X
881880
connect( mActionCustomProjection, SIGNAL( triggered() ), this, SLOT( customProjection() ) );
882881

883882
#ifdef Q_WS_MAC
@@ -886,11 +885,11 @@ void QgisApp::createActions()
886885
mActionWindowMinimize = new QAction( tr( "Minimize" ), this );
887886
mActionWindowMinimize->setShortcut( tr( "Ctrl+M", "Minimize Window" ) );
888887
mActionWindowMinimize->setStatusTip( tr( "Minimizes the active window to the dock" ) );
889-
connect( mActionWindowMinimize, SIGNAL( triggered() ), this, SLOT( showMinimized() ) );
888+
connect( mActionWindowMinimize, SIGNAL( triggered() ), this, SLOT( showActiveWindowMinimized() ) );
890889

891890
mActionWindowZoom = new QAction( tr( "Zoom" ), this );
892891
mActionWindowZoom->setStatusTip( tr( "Toggles between a predefined size and the window size set by the user" ) );
893-
connect( mActionWindowZoom, SIGNAL( triggered() ), this, SLOT( toggleMaximized() ) );
892+
connect( mActionWindowZoom, SIGNAL( triggered() ), this, SLOT( toggleActiveWindowMaximized() ) );
894893

895894
mActionWindowAllToFront = new QAction( tr( "Bring All to Front" ), this );
896895
mActionWindowAllToFront->setStatusTip( tr( "Bring forward all open windows" ) );
@@ -924,6 +923,7 @@ void QgisApp::createActions()
924923

925924
mActionAbout = new QAction( getThemeIcon( "mActionHelpAbout.png" ), tr( "About" ), this );
926925
mActionAbout->setStatusTip( tr( "About QGIS" ) );
926+
mActionAbout->setMenuRole( QAction::AboutRole ); // put in application menu on Mac OS X
927927
connect( mActionAbout, SIGNAL( triggered() ), this, SLOT( about() ) );
928928
}
929929

@@ -3530,10 +3530,30 @@ void QgisApp::toggleFullScreen()
35303530
}
35313531
}
35323532

3533-
void QgisApp::toggleMaximized()
3533+
void QgisApp::showActiveWindowMinimized()
35343534
{
3535-
if ( isMaximized() ) showNormal();
3536-
else showMaximized();
3535+
QWidget *window = QApplication::activeWindow();
3536+
if ( window )
3537+
{
3538+
window->showMinimized();
3539+
}
3540+
}
3541+
3542+
void QgisApp::toggleActiveWindowMaximized()
3543+
{
3544+
QWidget *window = QApplication::activeWindow();
3545+
if ( window )
3546+
{
3547+
if ( window->isMaximized() ) window->showNormal();
3548+
else window->showMaximized();
3549+
}
3550+
}
3551+
3552+
void QgisApp::activate()
3553+
{
3554+
raise();
3555+
setWindowState( windowState() & ~Qt::WindowMinimized );
3556+
activateWindow();
35373557
}
35383558

35393559
void QgisApp::bringAllToFront()
@@ -3549,10 +3569,17 @@ void QgisApp::bringAllToFront()
35493569
#ifdef Q_WS_MAC
35503570
void QgisApp::addWindow( QAction *action )
35513571
{
3552-
mWindowMenu->addAction( action );
35533572
mWindowActions->addAction( action );
3573+
mWindowMenu->addAction( action );
3574+
action->setCheckable( true );
35543575
action->setChecked( true );
35553576
}
3577+
3578+
void QgisApp::removeWindow( QAction *action )
3579+
{
3580+
mWindowActions->removeAction( action );
3581+
mWindowMenu->removeAction( action );
3582+
}
35563583
#endif
35573584

35583585
void QgisApp::stopRendering()
@@ -4657,13 +4684,31 @@ bool QgisApp::saveDirty()
46574684

46584685
void QgisApp::changeEvent( QEvent* event )
46594686
{
4687+
QMainWindow::changeEvent( event );
46604688
#ifdef Q_WS_MAC
4661-
if ( event->type() == QEvent::WindowTitleChange )
4689+
switch ( event->type() )
46624690
{
4691+
case QEvent::ActivationChange:
4692+
if ( QApplication::activeWindow() == this )
4693+
{
4694+
mWindowAction->setChecked( true );
4695+
}
4696+
// this should not be necessary since the action is part of an action group
4697+
// however this check is not cleared if PrintComposer is closed and reopened
4698+
else
4699+
{
4700+
mWindowAction->setChecked( false );
4701+
}
4702+
break;
4703+
4704+
case QEvent::WindowTitleChange:
46634705
mWindowAction->setText( windowTitle() );
4706+
break;
4707+
4708+
default:
4709+
break;
46644710
}
46654711
#endif
4666-
QWidget::changeEvent( event );
46674712
}
46684713

46694714
void QgisApp::closeEvent( QCloseEvent* event )

0 commit comments

Comments
 (0)
Please sign in to comment.