added clock to statusbar (can be disabled in settings)
Dieser Commit ist enthalten in:
Ursprung
469372f4e6
Commit
2a5acb8d88
@ -40,6 +40,8 @@ file(GLOB SOURCES
|
||||
"src/board/*.cpp"
|
||||
"src/dialog/*.hpp"
|
||||
"src/dialog/*.cpp"
|
||||
"src/mainwindow/*.hpp"
|
||||
"src/mainwindow/*.cpp"
|
||||
"src/misc/*.hpp"
|
||||
"src/misc/*.cpp"
|
||||
"src/network/*.hpp"
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
|
||||
#include "mainwindow.hpp"
|
||||
#include <QMenuBar>
|
||||
#include <QStatusBar>
|
||||
#include <QMdiSubWindow>
|
||||
#include <QVBoxLayout>
|
||||
#include <QToolBar>
|
||||
@ -38,6 +37,7 @@
|
||||
#include <traintastic/set/worldstate.hpp>
|
||||
#include <traintastic/utils/standardpaths.hpp>
|
||||
#include "mdiarea.hpp"
|
||||
#include "mainwindow/mainwindowstatusbar.hpp"
|
||||
#include "dialog/connectdialog.hpp"
|
||||
#include "settings/settingsdialog.hpp"
|
||||
#include "dialog/worldlistdialog.hpp"
|
||||
@ -99,6 +99,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
QMainWindow(parent),
|
||||
m_splitter{new QSplitter(Qt::Vertical, this)},
|
||||
m_mdiArea{new MdiArea(m_splitter)},
|
||||
m_statusBar{new MainWindowStatusBar(*this)},
|
||||
m_serverLog{nullptr},
|
||||
m_toolbar{new QToolBar(this)}
|
||||
{
|
||||
@ -514,7 +515,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
m_splitter->setCollapsible(0, false);
|
||||
|
||||
setCentralWidget(m_splitter);
|
||||
setStatusBar(new QStatusBar());
|
||||
setStatusBar(m_statusBar);
|
||||
|
||||
QSettings settings;
|
||||
if(settings.contains(SETTING_GEOMETRY))
|
||||
@ -585,6 +586,7 @@ void MainWindow::worldChanged()
|
||||
m_clockAction->setEnabled(false);
|
||||
m_clockAction->setChecked(false);
|
||||
m_clock.reset();
|
||||
emit worldClockChanged();
|
||||
|
||||
if(m_connection)
|
||||
{
|
||||
@ -602,6 +604,7 @@ void MainWindow::worldChanged()
|
||||
if(auto* freeze = object->getProperty("freeze"))
|
||||
{
|
||||
m_clock = object;
|
||||
emit worldClockChanged();
|
||||
m_clockAction->setEnabled(true);
|
||||
m_clockAction->setChecked(!freeze->toBool());
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "subwindow/subwindowtype.hpp"
|
||||
|
||||
class MdiArea;
|
||||
class MainWindowStatusBar;
|
||||
class QSplitter;
|
||||
class QActionGroup;
|
||||
class QToolButton;
|
||||
@ -52,6 +53,7 @@ class MainWindow : public QMainWindow
|
||||
ObjectPtr m_clock;
|
||||
QSplitter* m_splitter;
|
||||
MdiArea* m_mdiArea;
|
||||
MainWindowStatusBar* m_statusBar;
|
||||
ServerLogWidget* m_serverLog;
|
||||
QMap<QString, SubWindow*> m_subWindows;
|
||||
// Main menu:
|
||||
@ -119,10 +121,15 @@ class MainWindow : public QMainWindow
|
||||
|
||||
const std::shared_ptr<Connection>& connection() { return m_connection; }
|
||||
|
||||
const ObjectPtr& worldClock() const { return m_clock; }
|
||||
|
||||
public slots:
|
||||
void connectToServer(const QString& url = QString());
|
||||
void showObject(const ObjectPtr& object, SubWindowType flags = SubWindowType::Object);
|
||||
void showObject(const QString& id, const QString& title = "", SubWindowType flags = SubWindowType::Object);
|
||||
|
||||
signals:
|
||||
void worldClockChanged();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
76
client/src/mainwindow/mainwindowstatusbar.cpp
Normale Datei
76
client/src/mainwindow/mainwindowstatusbar.cpp
Normale Datei
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* client/src/mainwindow/mainwindowstatusbar.cpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "mainwindowstatusbar.hpp"
|
||||
#include <QLabel>
|
||||
#include "../mainwindow.hpp"
|
||||
#include "../network/object.hpp"
|
||||
#include "../network/abstractproperty.hpp"
|
||||
#include "../settings/statusbarsettings.hpp"
|
||||
|
||||
MainWindowStatusBar::MainWindowStatusBar(MainWindow& mainWindow)
|
||||
: QStatusBar(&mainWindow)
|
||||
, m_mainWindow{mainWindow}
|
||||
, m_clockLabel{new QLabel(this)}
|
||||
{
|
||||
// clock:
|
||||
m_clockLabel->setMinimumWidth(m_clockLabel->fontMetrics().averageCharWidth() * 5);
|
||||
m_clockLabel->setAlignment(Qt::AlignRight);
|
||||
addPermanentWidget(m_clockLabel);
|
||||
connect(&m_mainWindow, &MainWindow::worldClockChanged,
|
||||
[this]()
|
||||
{
|
||||
if(const auto& clock = m_mainWindow.worldClock())
|
||||
if(const auto* minute = clock->getProperty("minute"))
|
||||
connect(minute, &AbstractProperty::valueChanged, this, &MainWindowStatusBar::updateClock);
|
||||
});
|
||||
|
||||
// settings:
|
||||
connect(&StatusBarSettings::instance(), &StatusBarSettings::changed, this, &MainWindowStatusBar::settingsChanged);
|
||||
settingsChanged();
|
||||
}
|
||||
|
||||
void MainWindowStatusBar::settingsChanged()
|
||||
{
|
||||
clockChanged();
|
||||
}
|
||||
|
||||
void MainWindowStatusBar::clockChanged()
|
||||
{
|
||||
const bool visible = StatusBarSettings::instance().showClock.value();
|
||||
|
||||
if(m_clockLabel->isVisible() == visible)
|
||||
return;
|
||||
|
||||
if(visible)
|
||||
updateClock();
|
||||
|
||||
m_clockLabel->setVisible(visible);
|
||||
}
|
||||
|
||||
void MainWindowStatusBar::updateClock()
|
||||
{
|
||||
if(const auto& clock = m_mainWindow.worldClock())
|
||||
m_clockLabel->setText(QString("%1:%2").arg(clock->getPropertyValueInt("hour", 0)).arg(clock->getPropertyValueInt("minute", 0), 2, 10, QChar('0')));
|
||||
else
|
||||
m_clockLabel->setText("--:--");
|
||||
}
|
||||
45
client/src/mainwindow/mainwindowstatusbar.hpp
Normale Datei
45
client/src/mainwindow/mainwindowstatusbar.hpp
Normale Datei
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* client/src/mainwindow/mainwindowstatusbar.hpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TRAINTASTIC_CLIENT_MAINWINDOW_MAINWINDOWSTATUSBAR_HPP
|
||||
#define TRAINTASTIC_CLIENT_MAINWINDOW_MAINWINDOWSTATUSBAR_HPP
|
||||
|
||||
#include <QStatusBar>
|
||||
|
||||
class MainWindow;
|
||||
class QLabel;
|
||||
|
||||
class MainWindowStatusBar : public QStatusBar
|
||||
{
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
QLabel* m_clockLabel;
|
||||
|
||||
void settingsChanged();
|
||||
void clockChanged();
|
||||
void updateClock();
|
||||
|
||||
public:
|
||||
MainWindowStatusBar(MainWindow& mainWindow);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -62,6 +62,13 @@ bool Object::getPropertyValueBool(const QString& name, bool defaultValue) const
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
int Object::getPropertyValueInt(const QString& name, int defaultValue) const
|
||||
{
|
||||
if(const auto* property = getProperty(name); property && property->type() == ValueType::Integer)
|
||||
return property->toInt();
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
const AbstractVectorProperty* Object::getVectorProperty(const QString& name) const
|
||||
{
|
||||
return dynamic_cast<AbstractVectorProperty*>(m_interfaceItems.find(name));
|
||||
|
||||
@ -75,6 +75,14 @@ class Object : public QObject
|
||||
*/
|
||||
bool getPropertyValueBool(const QString& name, bool defaultValue) const;
|
||||
|
||||
/**
|
||||
* \brief Get integer property value
|
||||
* \param[in] name Property name
|
||||
* \param[in] defaultValue Value to return if property doesn't exist or isn't an integer
|
||||
* \return Property value or \c defaultValue if property doesn't exist or isn't an integer
|
||||
*/
|
||||
int getPropertyValueInt(const QString& name, int defaultValue) const;
|
||||
|
||||
inline bool hasVectorProperty(const QString& name) const { return getVectorProperty(name); }
|
||||
const AbstractVectorProperty* getVectorProperty(const QString& name) const;
|
||||
AbstractVectorProperty* getVectorProperty(const QString& name);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2021 Reinder Feenstra
|
||||
* Copyright (C) 2019-2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -27,6 +27,7 @@
|
||||
#include <QPushButton>
|
||||
#include <traintastic/locale/locale.hpp>
|
||||
#include "generalsettingswidget.hpp"
|
||||
#include "statusbarsettingswidget.hpp"
|
||||
#include "boardsettingswidget.hpp"
|
||||
#include "developersettingswidget.hpp"
|
||||
|
||||
@ -38,6 +39,7 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
|
||||
setWindowTitle(Locale::tr("qtapp.mainmenu:settings"));
|
||||
|
||||
add(new GeneralSettingsWidget(this));
|
||||
add(new StatusBarSettingsWidget(this));
|
||||
add(new BoardSettingsWidget(this));
|
||||
add(new DeveloperSettingsWidget(this));
|
||||
|
||||
|
||||
48
client/src/settings/statusbarsettings.hpp
Normale Datei
48
client/src/settings/statusbarsettings.hpp
Normale Datei
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* client/src/settings/statusbarsettings.hpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TRAINTASTIC_CLIENT_SETTINGS_STATUSBARSETTINGS_HPP
|
||||
#define TRAINTASTIC_CLIENT_SETTINGS_STATUSBARSETTINGS_HPP
|
||||
|
||||
#include "settingsbase.hpp"
|
||||
#include "setting.hpp"
|
||||
|
||||
class StatusBarSettings : public SettingsBase
|
||||
{
|
||||
private:
|
||||
StatusBarSettings()
|
||||
: SettingsBase("statusbar")
|
||||
, showClock{*this, "show_clock", true}
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
static StatusBarSettings& instance()
|
||||
{
|
||||
static StatusBarSettings settings;
|
||||
return settings;
|
||||
}
|
||||
|
||||
Setting<bool> showClock;
|
||||
};
|
||||
|
||||
#endif
|
||||
34
client/src/settings/statusbarsettingswidget.cpp
Normale Datei
34
client/src/settings/statusbarsettingswidget.cpp
Normale Datei
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* client/src/settings/statusbarsettingswidget.cpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "statusbarsettingswidget.hpp"
|
||||
#include "statusbarsettings.hpp"
|
||||
|
||||
StatusBarSettingsWidget::StatusBarSettingsWidget(QWidget* parent)
|
||||
: SettingsBaseWidget("qtapp.settings.statusbar", parent)
|
||||
{
|
||||
StatusBarSettings& s = StatusBarSettings::instance();
|
||||
|
||||
addSetting(s.showClock);
|
||||
|
||||
done();
|
||||
}
|
||||
36
client/src/settings/statusbarsettingswidget.hpp
Normale Datei
36
client/src/settings/statusbarsettingswidget.hpp
Normale Datei
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* client/src/settings/statusbarsettingswidget.hpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TRAINTASTIC_CLIENT_SETTINGS_STATUSBARSETTINGSWIDGET_HPP
|
||||
#define TRAINTASTIC_CLIENT_SETTINGS_STATUSBARSETTINGSWIDGET_HPP
|
||||
|
||||
#include "settingsbasewidget.hpp"
|
||||
|
||||
class StatusBarSettingsWidget : public SettingsBaseWidget
|
||||
{
|
||||
public:
|
||||
StatusBarSettingsWidget(QWidget* parent = nullptr);
|
||||
|
||||
QString title() const final { return QStringLiteral("qtapp.settings:statusbar"); }
|
||||
};
|
||||
|
||||
#endif
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren