Commit 3360ba16 authored by Alexander Semke's avatar Alexander Semke
Browse files

Introduce an option to determine what should be shown in the title bar -

file path, file name or project name. Furthermore, fixed the regression
with the window mode being not applied after the settings were changed.
parent 9e557c33
......@@ -308,9 +308,13 @@ void MainWin::initGUI(const QString& fileName) {
//load recently used projects
m_recentProjectsAction->loadEntries( KSharedConfig::openConfig()->group("Recent Files") );
//General Settings
const KConfigGroup& group = KSharedConfig::openConfig()->group("Settings_General");
//title bar
m_titleBarMode = static_cast<MainWin::TitleBarMode>(group.readEntry("TitleBar", 0));
//auto-save
KConfigGroup group = KSharedConfig::openConfig()->group("Settings_General");
m_autoSaveActive = group.readEntry<bool>("AutoSave", false);
int interval = group.readEntry("AutoSaveInterval", 1);
interval = interval*60*1000;
......@@ -862,10 +866,7 @@ void MainWin::updateGUIOnProjectChanges() {
factory->container("edit", this)->setEnabled(!b);
factory->container("import", this)->setEnabled(!b);
if (b)
setCaption("LabPlot2");
else
setCaption(m_project->name());
updateTitleBar();
#ifdef Q_OS_MAC
m_touchBar->clear();
......@@ -1176,7 +1177,7 @@ bool MainWin::newProject() {
connect(m_project, &Project::closeRequested, this, &MainWin::closeProject);
m_undoViewEmptyLabel = i18n("%1: created", m_project->name());
setCaption(m_project->name());
updateTitleBar();
return true;
}
......@@ -1382,7 +1383,7 @@ void MainWin::openProject(const QString& filename) {
m_project->undoStack()->clear();
m_undoViewEmptyLabel = i18n("%1: opened", m_project->name());
m_recentProjectsAction->addUrl( QUrl(filename) );
setCaption(m_project->name());
updateTitleBar();
updateGUIOnProjectChanges();
updateGUI(); //there are most probably worksheets or spreadsheets in the open project -> update the GUI
m_saveAction->setEnabled(false);
......@@ -1530,7 +1531,7 @@ bool MainWin::save(const QString& fileName) {
// do not rename temp file. Qt still holds a handle (which fails renaming on Windows) and deletes it
bool rc = QFile::copy(tempFileName, fileName);
if (rc) {
setCaption(m_project->name());
updateTitleBar();
statusBar()->showMessage(i18n("Project saved"));
m_saveAction->setEnabled(false);
m_recentProjectsAction->addUrl( QUrl(fileName) );
......@@ -1574,6 +1575,36 @@ void MainWin::autoSaveProject() {
this->saveProject();
}
void MainWin::updateTitleBar() {
QString title;
if (m_project) {
switch (m_titleBarMode) {
case TitleBarMode::ShowProjectName:
title = m_project->name();
break;
case TitleBarMode::ShowFileName:
if (m_project->fileName().isEmpty())
title = m_project->name();
else {
QFileInfo fi(m_project->fileName());
title = fi.baseName();
}
break;
case TitleBarMode::ShowFilePath:
if (m_project->fileName().isEmpty())
title = m_project->name();
else
title = m_project->fileName();
}
if (m_project->hasChanged())
title += QLatin1String(" [") + i18n("Changed") + QLatin1Char(']');
} else
title = QLatin1String("LabPlot");
setCaption(title);
}
/*!
prints the current sheet (worksheet, spreadsheet or matrix)
*/
......@@ -1728,7 +1759,7 @@ void MainWin::newCantorWorksheet(QAction* action) {
Adds "changed" to the window caption and activates the save-Action.
*/
void MainWin::projectChanged() {
setCaption(i18n("%1 [Changed]", m_project->name()));
updateTitleBar();
m_saveAction->setEnabled(true);
m_undoAction->setEnabled(true);
return;
......@@ -1937,7 +1968,7 @@ void MainWin::undo() {
WAIT_CURSOR;
m_project->undoStack()->undo();
if (m_project->undoStack()->index() == 0) {
setCaption(m_project->name());
updateTitleBar();
m_saveAction->setEnabled(false);
m_undoAction->setEnabled(false);
m_project->setChanged(false);
......@@ -2166,24 +2197,32 @@ void MainWin::dropEvent(QDropEvent* event) {
void MainWin::handleSettingsChanges() {
const KConfigGroup group = KSharedConfig::openConfig()->group( "Settings_General" );
//title bar
MainWin::TitleBarMode titleBarMode = static_cast<MainWin::TitleBarMode>(group.readEntry("TitleBar", 0));
if (titleBarMode != m_titleBarMode) {
m_titleBarMode = titleBarMode;
updateTitleBar();
}
//view mode
// if(dynamic_cast<QQuickWidget*>(centralWidget()) == nullptr) {
// QMdiArea::ViewMode viewMode = QMdiArea::ViewMode(group.readEntry("ViewMode", 0));
// if (m_mdiArea->viewMode() != viewMode) {
// m_mdiArea->setViewMode(viewMode);
// if (viewMode == QMdiArea::SubWindowView)
// this->updateMdiWindowVisibility();
// }
//
// if (m_mdiArea->viewMode() == QMdiArea::TabbedView) {
// m_tileWindowsAction->setVisible(false);
// m_cascadeWindowsAction->setVisible(false);
// QTabWidget::TabPosition tabPosition = QTabWidget::TabPosition(group.readEntry("TabPosition", 0));
// if (m_mdiArea->tabPosition() != tabPosition)
// m_mdiArea->setTabPosition(tabPosition);
// } else {
// m_tileWindowsAction->setVisible(true);
// m_cascadeWindowsAction->setVisible(true);
// }
QMdiArea::ViewMode viewMode = QMdiArea::ViewMode(group.readEntry("ViewMode", 0));
if (m_mdiArea->viewMode() != viewMode) {
m_mdiArea->setViewMode(viewMode);
if (viewMode == QMdiArea::SubWindowView)
this->updateMdiWindowVisibility();
}
if (m_mdiArea->viewMode() == QMdiArea::TabbedView) {
m_tileWindowsAction->setVisible(false);
m_cascadeWindowsAction->setVisible(false);
QTabWidget::TabPosition tabPosition = QTabWidget::TabPosition(group.readEntry("TabPosition", 0));
if (m_mdiArea->tabPosition() != tabPosition)
m_mdiArea->setTabPosition(tabPosition);
} else {
m_tileWindowsAction->setVisible(true);
m_cascadeWindowsAction->setVisible(true);
}
// }
//autosave
......
......@@ -121,6 +121,7 @@ public:
void addAspectToProject(AbstractAspect*);
enum class LoadOnStart {Nothing, NewProject, NewProjectWorksheet, LastProject, WelcomeScreen};
enum class TitleBarMode {ShowFilePath, ShowFileName, ShowProjectName};
#ifdef HAVE_KUSERFEEDBACK
KUserFeedback::Provider& userFeedbackProvider() {return m_userFeedbackProvider;}
......@@ -154,6 +155,7 @@ private:
// WelcomeScreenHelper* m_welcomeScreenHelper{nullptr};
ImportDatasetWidget* m_importDatasetWidget{nullptr};
QString m_lastOpenFileFilter;
TitleBarMode m_titleBarMode{TitleBarMode::ShowFilePath};
#ifdef HAVE_KUSERFEEDBACK
KUserFeedback::Provider m_userFeedbackProvider;
......@@ -291,6 +293,7 @@ private slots:
bool saveProject();
bool saveProjectAs();
void autoSaveProject();
void updateTitleBar();
void print();
void printPreview();
......
......@@ -3,7 +3,7 @@
Project : LabPlot
Description : general settings page
--------------------------------------------------------------------
Copyright : (C) 2008-2018 Alexander Semke (alexander.semke@web.de)
Copyright : (C) 2008-2020 Alexander Semke (alexander.semke@web.de)
***************************************************************************/
......@@ -40,16 +40,12 @@ SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent)
ui.sbAutoSaveInterval->setSuffix(i18n("min."));
retranslateUi();
connect(ui.cbLoadOnStart, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SettingsGeneralPage::changed);
connect(ui.cbInterface, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SettingsGeneralPage::interfaceChanged);
connect(ui.cbMdiVisibility, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SettingsGeneralPage::changed);
connect(ui.cbTabPosition, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SettingsGeneralPage::changed);
connect(ui.cbUnits, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SettingsGeneralPage::changed);
connect(ui.cbLoadOnStart, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.cbTitleBar, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.cbInterface, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::interfaceChanged);
connect(ui.cbMdiVisibility, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.cbTabPosition, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.cbUnits, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.chkAutoSave, &QCheckBox::stateChanged, this, &SettingsGeneralPage::autoSaveChanged);
connect(ui.chkMemoryInfo, &QCheckBox::stateChanged, this, &SettingsGeneralPage::changed);
......@@ -61,6 +57,7 @@ SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent)
void SettingsGeneralPage::applySettings() {
KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
group.writeEntry(QLatin1String("LoadOnStart"), ui.cbLoadOnStart->currentIndex());
group.writeEntry(QLatin1String("TitleBar"), ui.cbTitleBar->currentIndex());
group.writeEntry(QLatin1String("ViewMode"), ui.cbInterface->currentIndex());
group.writeEntry(QLatin1String("TabPosition"), ui.cbTabPosition->currentIndex());
group.writeEntry(QLatin1String("MdiWindowVisibility"), ui.cbMdiVisibility->currentIndex());
......@@ -72,6 +69,7 @@ void SettingsGeneralPage::applySettings() {
void SettingsGeneralPage::restoreDefaults() {
ui.cbLoadOnStart->setCurrentIndex(0);
ui.cbTitleBar->setCurrentIndex(0);
ui.cbInterface->setCurrentIndex(0);
ui.cbTabPosition->setCurrentIndex(0);
ui.cbMdiVisibility->setCurrentIndex(0);
......@@ -85,6 +83,7 @@ void SettingsGeneralPage::restoreDefaults() {
void SettingsGeneralPage::loadSettings() {
const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
ui.cbLoadOnStart->setCurrentIndex(group.readEntry(QLatin1String("LoadOnStart"), 0));
ui.cbTitleBar->setCurrentIndex(group.readEntry(QLatin1String("TitleBar"), 0));
ui.cbInterface->setCurrentIndex(group.readEntry(QLatin1String("ViewMode"), 0));
ui.cbTabPosition->setCurrentIndex(group.readEntry(QLatin1String("TabPosition"), 0));
ui.cbMdiVisibility->setCurrentIndex(group.readEntry(QLatin1String("MdiWindowVisibility"), 0));
......@@ -102,6 +101,11 @@ void SettingsGeneralPage::retranslateUi() {
ui.cbLoadOnStart->addItem(i18n("Load last used project"));
// ui.cbLoadOnStart->addItem(i18n("Show Welcome Screen"));
ui.cbTitleBar->clear();
ui.cbTitleBar->addItem(i18n("Show File Path"));
ui.cbTitleBar->addItem(i18n("Show File Name"));
ui.cbTitleBar->addItem(i18n("Show Project Name"));
ui.cbInterface->clear();
ui.cbInterface->addItem(i18n("Sub-window view"));
ui.cbInterface->addItem(i18n("Tabbed view"));
......
......@@ -6,22 +6,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>774</width>
<height>380</height>
<width>613</width>
<height>387</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="7" column="3">
<widget class="QCheckBox" name="chkMemoryInfo">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Enabled</string>
<string>Startup:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer_2">
<item row="0" column="2">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
......@@ -29,86 +29,68 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>13</height>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lAutoSave">
<property name="text">
<string>Auto-Save:</string>
</property>
</widget>
<item row="0" column="3">
<widget class="KComboBox" name="cbLoadOnStart"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<item row="1" column="0">
<widget class="QLabel" name="lTitleBar">
<property name="text">
<string>Startup:</string>
<string>Title Bar:</string>
</property>
</widget>
</item>
<item row="6" column="5">
<widget class="QLabel" name="lAutoSaveInterval">
<property name="text">
<string>Interval:</string>
</property>
</widget>
<item row="1" column="3">
<widget class="QComboBox" name="cbTitleBar"/>
</item>
<item row="6" column="3">
<widget class="QCheckBox" name="chkAutoSave">
<item row="2" column="0">
<widget class="QLabel" name="lInterface">
<property name="text">
<string>Enabled</string>
<string>Interface:</string>
</property>
</widget>
</item>
<item row="0" column="3" colspan="5">
<widget class="KComboBox" name="cbLoadOnStart"/>
<item row="2" column="3">
<widget class="KComboBox" name="cbInterface"/>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="lTabPosition">
<property name="text">
<string>Tab position:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lInterface">
<property name="text">
<string>Interface:</string>
</property>
</widget>
<item row="3" column="3">
<widget class="KComboBox" name="cbTabPosition"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lMemoryInfo">
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="lMdiVisibility">
<property name="text">
<string>Show memory info:</string>
<string>Sub-window visibility:</string>
</property>
</widget>
</item>
<item row="3" column="3" colspan="5">
<item row="4" column="3">
<widget class="KComboBox" name="cbMdiVisibility"/>
</item>
<item row="6" column="7">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>327</width>
<height>17</height>
</size>
<item row="5" column="0">
<widget class="QLabel" name="lUnits">
<property name="text">
<string>Units</string>
</property>
</spacer>
</widget>
</item>
<item row="2" column="3" colspan="5">
<widget class="KComboBox" name="cbTabPosition"/>
<item row="5" column="3">
<widget class="QComboBox" name="cbUnits"/>
</item>
<item row="0" column="2">
<spacer>
<item row="6" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
......@@ -116,38 +98,110 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
<height>13</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="4">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<item row="7" column="0">
<widget class="QLabel" name="lAutoSave">
<property name="text">
<string>Auto-Save:</string>
</property>
</spacer>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="lMdiVisibility">
<item row="7" column="3">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="chkAutoSave">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lAutoSaveInterval">
<property name="text">
<string>Interval:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sbAutoSaveInterval">
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>137</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="lMemoryInfo">
<property name="text">
<string>Sub-window visibility:</string>
<string>Show memory info:</string>
</property>
</widget>
</item>
<item row="1" column="3" colspan="5">
<widget class="KComboBox" name="cbInterface"/>
<item row="8" column="3">
<widget class="QCheckBox" name="chkMemoryInfo">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -160,26 +214,6 @@
</property>
</spacer>
</item>
<item row="6" column="6">
<widget class="QSpinBox" name="sbAutoSaveInterval">
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lUnits">
<property name="text">
<string>Units</string>
</property>
</widget>
</item>
<item row="4" column="3" colspan="5">
<widget class="QComboBox" name="cbUnits"/>
</item>
</layout>
</widget>
<customwidgets>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment