From 3db3a6dd1deedda2373b0ee1f690edbf97dbdb23 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Tue, 8 Jan 2013 15:03:15 +0000 Subject: [PATCH] UI Nits: Sensible defaults for screen/font size Set the default size of fonts and screens based upon the screen size we're running on. We may need to think about retrospectively adjusting the font size for users that have not realised they can change from the defaults (which may not be valid for their hardware). --- src/Colors.cpp | 32 ++++++++++++++++++++++++++++++++ src/Colors.h | 22 ++++++++++++++++++++++ src/MainWindow.cpp | 33 +++++++++++++++++++++++++++++++-- src/MainWindow.h | 1 + 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/Colors.cpp b/src/Colors.cpp index 27390302d..930d60185 100644 --- a/src/Colors.cpp +++ b/src/Colors.cpp @@ -108,6 +108,38 @@ void GCColor::setupColors() copyArray(init, ColorList); } +// default settings for fonts etc +struct Appearance defaultAppearance[] ={ + + // small screens include netbooks and old vga 800x600, 1024x768 + { 1024, 768, 8,8,8,8,8,8, 800, 600 }, + + // medium screen size includes typical 16:9 pc formats and TV screens + { 1280, 800, 8,8,8,8,8,8, 800, 600}, + + // high resolution screens + { 1650, 1080, 11,11,11,11,11,11, 1024,650 }, + + // very big panels, incl. e.g. mac 27" + { 9999, 9999, 11,11,11,11,11,11, 1280,700 }, + + { 0,0,0,0,0,0,0,0,0,0 }, +}; + +struct Appearance +GCColor::defaultSizes(int width, int height) +{ + for (int i=0; defaultAppearance[i].maxheight; i++) { + + if (height > defaultAppearance[i].maxheight && width > defaultAppearance[i].maxwidth) + continue; + + else return defaultAppearance[i]; + + } + return defaultAppearance[0]; // shouldn't get here +} + GCColor::GCColor(MainWindow *main) : QObject(main) { setupColors(); diff --git a/src/Colors.h b/src/Colors.h index d3211d969..550183594 100644 --- a/src/Colors.h +++ b/src/Colors.h @@ -26,6 +26,27 @@ class MainWindow; +// set appearace defaults based upon screen size +struct Appearance { + + // this applies up to the following geometry + int maxheight, + maxwidth; + + // font size + int defaultFont, + titleFont, + markerFont, + labelFont, + calendarFont, + popupFont; + + // screen dimension + int width, + height; +}; + +extern Appearance defaultAppearance[]; struct Colors { QString name, @@ -46,6 +67,7 @@ class GCColor : public QObject static const Colors *defaultColorSet(); static void resetColors(); static QColor invert(QColor); + static struct Appearance defaultSizes(int width, int height); public slots: void readConfig(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 942ec973d..1b2373632 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -123,6 +123,7 @@ #include "TrainDB.h" QList mainwindows; // keep track of all the MainWindows we have open +QDesktopWidget *desktop = NULL; MainWindow::MainWindow(const QDir &home) : home(home), session(0), isclean(false), ismultisave(false), @@ -130,6 +131,7 @@ MainWindow::MainWindow(const QDir &home) : ride(NULL), workout(NULL) { + if (desktop == NULL) desktop = QApplication::desktop(); static const QIcon hideIcon(":images/toolbar/main/hideside.png"); static const QIcon rhideIcon(":images/toolbar/main/hiderside.png"); static const QIcon showIcon(":images/toolbar/main/showside.png"); @@ -159,11 +161,38 @@ MainWindow::MainWindow(const QDir &home) : setAttribute(Qt::WA_DeleteOnClose); + // need to restore geometry before setUnifiedToolBar.. on Mac appsettings->setValue(GC_SETTINGS_LAST, home.dirName()); QVariant geom = appsettings->value(this, GC_SETTINGS_MAIN_GEOM); - if (geom == QVariant()) resize(640, 480); - else setGeometry(geom.toRect()); + if (geom == QVariant()) { + + // first run -- lets set some sensible defaults... + // lets put it in the middle of screen 1 + QRect size = desktop->availableGeometry(); + struct Appearance app = GCColor::defaultSizes(size.height(), size.width()); + + // center on the available screen (minus toolbar/sidebar) + move((size.width()-size.x())/2 - app.width/2, + (size.height()-size.y())/2 - app.height/2); + + // set to the right default + resize(app.width, app.height); + + // set all the default font sizes + appsettings->setValue(GC_FONT_DEFAULT_SIZE, app.defaultFont); + appsettings->setValue(GC_FONT_TITLES_SIZE, app.titleFont); + appsettings->setValue(GC_FONT_CHARTMARKERS_SIZE, app.markerFont); + appsettings->setValue(GC_FONT_CHARTLABELS_SIZE, app.labelFont); + appsettings->setValue(GC_FONT_CALENDAR_SIZE, app.calendarFont); + appsettings->setValue(GC_FONT_POPUP_SIZE, app.popupFont); + + // set the default fontsize + QFont font; + font.setPointSize(app.defaultFont); + QApplication::setFont(font); + + } else setGeometry(geom.toRect()); #ifdef Q_OS_MAC // MAC NATIVE TOOLBAR diff --git a/src/MainWindow.h b/src/MainWindow.h index 5453d600f..d7edf9273 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -76,6 +76,7 @@ class BlankStateDiaryPage; class BlankStateTrainPage; extern QList mainwindows; // keep track of all the MainWindows we have open +extern QDesktopWidget *desktop; // how many screens / res etc class MainWindow : public QMainWindow {