Skip to content
Permalink
Browse files
Add Mac menubars for PrintComposer and AttributeTable windows.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9223 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Aug 31, 2008
1 parent b00b4a9 commit c6774f83fa7e5d7f40b0b1600c6999290c03820c
@@ -38,10 +38,12 @@
#include "qgscontexthelp.h"
#include "qgscursors.h"

#include <QCloseEvent>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QFileInfo>
#include <QMatrix>
#include <QMenuBar>
#include <QMessageBox>
#include <QPainter>

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

QString myIconPath = QgsApplication::activeThemePath();

QAction* moveItemContentAction = new QAction( QIcon( QPixmap( myIconPath + "mActionMoveItemContent.png" ) ), tr( "Move Item content" ), 0 );
// Actions defined in qgscomposerbase.ui:
// mActionAddNewMap
// mActionAddNewLegend
// mActionAddNewLabel
// mActionAddNewScalebar
// mActionAddImage
// mActionSelectMoveItem

QAction* moveItemContentAction = new QAction( QIcon( QPixmap( myIconPath + "mActionMoveItemContent.png" ) ),
tr( "Move Content" ), 0 );
moveItemContentAction->setToolTip( tr( "Move item content" ) );
moveItemContentAction->setCheckable( true );
connect( moveItemContentAction, SIGNAL( triggered() ), this, SLOT( moveItemContent() ) );
toolBar->addAction( moveItemContentAction );
//toolBar->addAction(QIcon(QPixmap(myIconPath+"mActionMoveItemContent.png")), tr("Move Item content"), this, SLOT(moveItemContent()));

toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionGroupItems.png" ) ), tr( "&Group Items" ), this, SLOT( groupItems() ) );
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionUngroupItems.png" ) ), tr( "&Ungroup Items" ), this, SLOT( ungroupItems() ) );
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionRaiseItems.png" ) ), tr( "Raise selected items" ), this, SLOT( raiseSelectedItems() ) );
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionLowerItems.png" ) ), tr( "Lower selected items" ), this, SLOT( lowerSelectedItems() ) );
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionMoveItemsToTop.png" ) ), tr( "Move selected items to top" ), this, SLOT( moveSelectedItemsToTop() ) );
toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionMoveItemsToBottom.png" ) ), tr( "Move selected items to bottom" ), this, SLOT( moveSelectedItemsToBottom() ) );
QAction* groupItemsAction = toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionGroupItems.png" ) ),
tr( "&Group" ), this, SLOT( groupItems() ) );
groupItemsAction->setToolTip( tr( "Group items" ) );
QAction* ungroupItemsAction = toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionUngroupItems.png" ) ),
tr( "&Ungroup" ), this, SLOT( ungroupItems() ) );
ungroupItemsAction->setToolTip( tr( "Ungroup items" ) );
QAction* raiseItemsAction = toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionRaiseItems.png" ) ),
tr( "Raise" ), this, SLOT( raiseSelectedItems() ) );
raiseItemsAction->setToolTip( tr( "Raise selected items" ) );
QAction* lowerItemsAction = toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionLowerItems.png" ) ),
tr( "Lower" ), this, SLOT( lowerSelectedItems() ) );
lowerItemsAction->setToolTip( tr( "Lower selected items" ) );
QAction* moveItemsToTopAction = toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionMoveItemsToTop.png" ) ),
tr( "Bring to Front" ), this, SLOT( moveSelectedItemsToTop() ) );
moveItemsToTopAction->setToolTip( tr( "Move selected items to top" ) );
QAction* moveItemsToBottomAction = toolBar->addAction( QIcon( QPixmap( myIconPath + "mActionMoveItemsToBottom.png" ) ),
tr( "Send to Back" ), this, SLOT( moveSelectedItemsToBottom() ) );
moveItemsToBottomAction->setToolTip( tr( "Move selected items to bottom" ) );

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

#ifdef Q_WS_MAC
QMenu *appMenu = menuBar()->addMenu( tr( "QGIS" ) );
appMenu->addAction( QgisApp::instance()->actionAbout() );
appMenu->addAction( QgisApp::instance()->actionOptions() );

QMenu *fileMenu = menuBar()->addMenu( tr( "File" ) );
fileMenu->addAction( mActionOpenTemplate );
fileMenu->addSeparator();
QAction *closeAction = fileMenu->addAction( tr( "Close" ), this, SLOT( close() ), tr( "Ctrl+W" ) );
fileMenu->addAction( mActionSaveTemplateAs );
fileMenu->addAction( mActionExportAsImage );
fileMenu->addAction( mActionExportAsSVG );
fileMenu->addSeparator();
fileMenu->addAction( mActionPrint );

QMenu *editMenu = menuBar()->addMenu( tr( "Edit" ) );
QAction *undoAction = editMenu->addAction( tr( "&Undo" ), this, SLOT( undo() ), tr( "Ctrl+Z" ) );
undoAction->setEnabled( false );
editMenu->addSeparator();
QAction *cutAction = editMenu->addAction( tr( "Cu&t" ), this, SLOT( cut() ), tr( "Ctrl+X" ) );
cutAction->setEnabled( false );
QAction *copyAction = editMenu->addAction( tr( "&Copy" ), this, SLOT( copy() ), tr( "Ctrl+C" ) );
copyAction->setEnabled( false );
QAction *pasteAction = editMenu->addAction( tr( "&Paste" ), this, SLOT( paste() ), tr( "Ctrl+V" ) );
pasteAction->setEnabled( false );
QAction *deleteAction = editMenu->addAction( tr( "Delete" ) );
deleteAction->setEnabled( false );

QMenu *viewMenu = menuBar()->addMenu( tr( "View" ) );
viewMenu->addAction( mActionZoomIn );
viewMenu->addAction( mActionZoomOut );
viewMenu->addAction( mActionZoomAll );
viewMenu->addSeparator();
viewMenu->addAction( mActionRefreshView );

QMenu *layoutMenu = menuBar()->addMenu( tr( "Layout" ) );
layoutMenu->addAction( mActionAddNewMap );
layoutMenu->addAction( mActionAddNewLabel );
layoutMenu->addAction( mActionAddNewScalebar );
layoutMenu->addAction( mActionAddNewLegend );
layoutMenu->addAction( mActionAddImage );
layoutMenu->addAction( mActionSelectMoveItem );
layoutMenu->addAction( moveItemContentAction );
layoutMenu->addSeparator();
layoutMenu->addAction( groupItemsAction );
layoutMenu->addAction( ungroupItemsAction );
layoutMenu->addAction( raiseItemsAction );
layoutMenu->addAction( lowerItemsAction );
layoutMenu->addAction( moveItemsToTopAction );
layoutMenu->addAction( moveItemsToBottomAction );

#ifndef Q_WS_MAC64 /* assertion failure in NSMenuItem setSubmenu (Qt 4.5.0-snapshot-20080830) */
menuBar()->addMenu( QgisApp::instance()->windowMenu() );

menuBar()->addMenu( QgisApp::instance()->helpMenu() );
#endif

// Create action to select this window and add it to Window menu
mWindowAction = new QAction( windowTitle(), this );
connect( mWindowAction, SIGNAL( triggered() ), this, SLOT( activate() ) );
#endif

mQgis = qgis;
mFirstTime = true;

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

void QgsComposer::activate()
{
raise();
setWindowState( windowState() & ~Qt::WindowMinimized );
activateWindow();
}

#ifdef Q_WS_MAC
void QgsComposer::changeEvent( QEvent* event )
{
QMainWindow::changeEvent( event );
switch ( event->type() )
{
case QEvent::ActivationChange:
if ( QApplication::activeWindow() == this )
{
mWindowAction->setChecked( true );
}
break;

default:
break;
}
}

void QgsComposer::closeEvent( QCloseEvent *event )
{
QMainWindow::closeEvent( event );
if ( event->isAccepted() )
{
QgisApp::instance()->removeWindow( mWindowAction );
}
}

void QgsComposer::showEvent( QShowEvent *event )
{
QMainWindow::showEvent( event );
// add to menu if (re)opening window (event not due to unminimize)
if ( !event->spontaneous() )
{
QgisApp::instance()->addWindow( mWindowAction );
}
}
#endif

void QgsComposer::showCompositionOptions( QWidget *w )
{
QWidget* currentWidget = mItemStackedWidget->currentWidget();
@@ -92,11 +92,23 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Restore the window and toolbar state
void restoreWindowState();

protected:
//! Move event
void moveEvent( QMoveEvent * );
virtual void moveEvent( QMoveEvent * );

//! Resize event
void resizeEvent( QResizeEvent * );
virtual void resizeEvent( QResizeEvent * );

#ifdef Q_WS_MAC
//! Change event (update window menu on ActivationChange)
virtual void changeEvent( QEvent * );

//! Close event (remove window from menu)
virtual void closeEvent( QCloseEvent * );

//! Show event (add window to menu)
virtual void showEvent( QShowEvent * );
#endif

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

void setSelectionTool();

private slots:

//! Raise, unminimize and activate this window
void activate();

private:
//! Set teh pixmap / icons on the toolbar buttons
//! Set the pixmap / icons on the toolbar buttons
void setupTheme();
/**Etablishes the signal slot connection for the class*/
/**Establishes the signal slot connection for the class*/
void connectSlots();

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

#ifdef Q_WS_MAC
//! Window menu action to select this window
QAction *mWindowAction;
#endif

//! Help context id
static const int context_id = 985715179;

@@ -368,7 +368,6 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
#ifdef Q_WS_MAC
// action for Window menu (create before generating WindowTitleChange event))
mWindowAction = new QAction( this );
mWindowAction->setCheckable( true );
connect( mWindowAction, SIGNAL( triggered() ), this, SLOT( activate() ) );

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

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

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

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

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

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

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

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

void QgisApp::toggleMaximized()
void QgisApp::showActiveWindowMinimized()
{
if ( isMaximized() ) showNormal();
else showMaximized();
QWidget *window = QApplication::activeWindow();
if ( window )
{
window->showMinimized();
}
}

void QgisApp::toggleActiveWindowMaximized()
{
QWidget *window = QApplication::activeWindow();
if ( window )
{
if ( window->isMaximized() ) window->showNormal();
else window->showMaximized();
}
}

void QgisApp::activate()
{
raise();
setWindowState( windowState() & ~Qt::WindowMinimized );
activateWindow();
}

void QgisApp::bringAllToFront()
@@ -3549,10 +3569,17 @@ void QgisApp::bringAllToFront()
#ifdef Q_WS_MAC
void QgisApp::addWindow( QAction *action )
{
mWindowMenu->addAction( action );
mWindowActions->addAction( action );
mWindowMenu->addAction( action );
action->setCheckable( true );
action->setChecked( true );
}

void QgisApp::removeWindow( QAction *action )
{
mWindowActions->removeAction( action );
mWindowMenu->removeAction( action );
}
#endif

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

void QgisApp::changeEvent( QEvent* event )
{
QMainWindow::changeEvent( event );
#ifdef Q_WS_MAC
if ( event->type() == QEvent::WindowTitleChange )
switch ( event->type() )
{
case QEvent::ActivationChange:
if ( QApplication::activeWindow() == this )
{
mWindowAction->setChecked( true );
}
// this should not be necessary since the action is part of an action group
// however this check is not cleared if PrintComposer is closed and reopened
else
{
mWindowAction->setChecked( false );
}
break;

case QEvent::WindowTitleChange:
mWindowAction->setText( windowTitle() );
break;

default:
break;
}
#endif
QWidget::changeEvent( event );
}

void QgisApp::closeEvent( QCloseEvent* event )

0 comments on commit c6774f8

Please sign in to comment.