Adjust width of mode list according to its contents. (#15)

Also added mode controls to File menu.
This commit is contained in:
Jim Evins
2018-05-21 21:45:53 -04:00
parent b729ee21d2
commit a3d07e8d9f
4 changed files with 521 additions and 326 deletions
+78 -3
View File
@@ -70,8 +70,6 @@ namespace glabels
mContents = new QListWidget();
mContents->setViewMode(QListView::ListMode);
mContents->setMovement(QListView::Static);
mContents->setMinimumWidth(96);
mContents->setMaximumWidth(96);
mContents->setSpacing(6);
// Pages widget
@@ -86,27 +84,37 @@ namespace glabels
// Add "Editor" page
mPages->addWidget( editorPage );
mEditorButton = new QListWidgetItem(mContents);
mEditorButton->setText(tr("Home"));
mEditorButton->setText(tr("Edit"));
mEditorButton->setToolTip( tr("Select <b>Edit</b> mode") );
mEditorButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
// Add "Properties" page
mPages->addWidget( propertiesPage );
mPropertiesButton = new QListWidgetItem(mContents);
mPropertiesButton->setText(tr("Properties"));
mPropertiesButton->setToolTip( tr("Select <b>Properties</b> mode") );
mPropertiesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
// Add "Merge" page
mPages->addWidget( mergePage );
mMergeButton = new QListWidgetItem(mContents);
mMergeButton->setText(tr("Merge"));
mMergeButton->setToolTip( tr("Select <b>Merge</b> mode") );
mMergeButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
// Add "Print" page
mPages->addWidget( printPage );
mPrintButton = new QListWidgetItem(mContents);
mPrintButton->setText(tr("Print"));
mPrintButton->setToolTip( tr("Select <b>Print</b> mode") );
mPrintButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
// Adjust width of list view based on its contents
mContents->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
mContents->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
mContents->setMinimumWidth( mContents->sizeHintForColumn(0) + 24 );
mContents->setMaximumWidth( mContents->sizeHintForColumn(0) + 24 );
// Set initial page selection
mWelcomeButton->setSelected( true );
mPages->setCurrentIndex(mContents->row(mWelcomeButton));
@@ -246,6 +254,26 @@ namespace glabels
fileSaveAsAction->setStatusTip( tr("Save current gLabels project to a different name") );
connect( fileSaveAsAction, SIGNAL(triggered()), this, SLOT(fileSaveAs()) );
fileShowEditorPageAction = new QAction( tr("&Edit") , this );
fileShowEditorPageAction->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_1 ) );
fileShowEditorPageAction->setStatusTip( tr("Select project Edit mode") );
connect( fileShowEditorPageAction, SIGNAL(triggered()), this, SLOT(fileShowEditorPage()) );
fileShowPropertiesPageAction = new QAction( tr("P&roperties") , this );
fileShowPropertiesPageAction->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_2 ) );
fileShowPropertiesPageAction->setStatusTip( tr("Select project Properties mode") );
connect( fileShowPropertiesPageAction, SIGNAL(triggered()), this, SLOT(fileShowPropertiesPage()) );
fileShowMergePageAction = new QAction( tr("&Merge") , this );
fileShowMergePageAction->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_3 ) );
fileShowMergePageAction->setStatusTip( tr("Select project Merge mode") );
connect( fileShowMergePageAction, SIGNAL(triggered()), this, SLOT(fileShowMergePage()) );
fileShowPrintPageAction = new QAction( tr("&Print") , this );
fileShowPrintPageAction->setShortcut( QKeySequence::Print );
fileShowPrintPageAction->setStatusTip( tr("Select project Print mode") );
connect( fileShowPrintPageAction, SIGNAL(triggered()), this, SLOT(fileShowPrintPage()) );
fileTemplateDesignerAction = new QAction( tr("Product Template &Designer..."), this );
fileTemplateDesignerAction->setStatusTip( tr("Create custom templates") );
connect( fileTemplateDesignerAction, SIGNAL(triggered()), this, SLOT(fileTemplateDesigner()) );
@@ -517,6 +545,11 @@ namespace glabels
fileMenu->addAction( fileSaveAction );
fileMenu->addAction( fileSaveAsAction );
fileMenu->addSeparator();
fileMenu->addAction( fileShowEditorPageAction );
fileMenu->addAction( fileShowPropertiesPageAction );
fileMenu->addAction( fileShowMergePageAction );
fileMenu->addAction( fileShowPrintPageAction );
fileMenu->addSeparator();
fileMenu->addAction( fileTemplateDesignerAction );
fileMenu->addSeparator();
fileMenu->addAction( fileCloseAction );
@@ -988,6 +1021,12 @@ namespace glabels
setSelectionVerbsEnabled( isEditorPage && !mModel->isSelectionEmpty() );
setMultiSelectionVerbsEnabled( isEditorPage && !mModel->isSelectionEmpty() && !mModel->isSelectionAtomic() );
setPasteVerbsEnabled( isEditorPage && mModel->canPaste() );
bool isWelcome = ( current == mWelcomeButton );
fileShowEditorPageAction->setEnabled( !isWelcome && (current != mEditorButton) );
fileShowPropertiesPageAction->setEnabled( !isWelcome && (current != mPropertiesButton) );
fileShowMergePageAction->setEnabled( !isWelcome && (current != mMergeButton) );
fileShowPrintPageAction->setEnabled( !isWelcome && (current != mPrintButton) );
}
@@ -1036,6 +1075,42 @@ namespace glabels
}
///
/// File->Show Editor Page
///
void MainWindow::fileShowEditorPage()
{
mContents->setCurrentItem( mEditorButton );
}
///
/// File->Show Properties Page
///
void MainWindow::fileShowPropertiesPage()
{
mContents->setCurrentItem( mPropertiesButton );
}
///
/// File->Show Merge Page
///
void MainWindow::fileShowMergePage()
{
mContents->setCurrentItem( mMergeButton );
}
///
/// File->Show Print Page
///
void MainWindow::fileShowPrintPage()
{
mContents->setCurrentItem( mPrintButton );
}
///
/// File->Template Designer Action
///
+8
View File
@@ -92,6 +92,10 @@ namespace glabels
void fileOpen();
void fileSave();
void fileSaveAs();
void fileShowEditorPage();
void fileShowPropertiesPage();
void fileShowMergePage();
void fileShowPrintPage();
void fileTemplateDesigner();
void fileClose();
void fileExit();
@@ -235,6 +239,10 @@ namespace glabels
QAction* fileOpenAction;
QAction* fileSaveAction;
QAction* fileSaveAsAction;
QAction* fileShowEditorPageAction;
QAction* fileShowPropertiesPageAction;
QAction* fileShowMergePageAction;
QAction* fileShowPrintPageAction;
QAction* fileTemplateDesignerAction;
QAction* fileCloseAction;
QAction* fileExitAction;