diff options
author | jjl | 2010-09-29 19:43:30 +0200 |
---|---|---|
committer | jjl | 2010-09-29 19:43:30 +0200 |
commit | 1e1b61682158b8925a17e0a22ad18b51abde24c6 (patch) | |
tree | 9d69b9115dca154df251d5e87446990df97829ce /src/pvsgui.cpp | |
parent | [PVSGUI] restart pvs daemon on startup (diff) | |
download | pvs-1e1b61682158b8925a17e0a22ad18b51abde24c6.tar.gz pvs-1e1b61682158b8925a17e0a22ad18b51abde24c6.tar.xz pvs-1e1b61682158b8925a17e0a22ad18b51abde24c6.zip |
[PVSGUI] set toolbar position via cmd-switch
Diffstat (limited to 'src/pvsgui.cpp')
-rw-r--r-- | src/pvsgui.cpp | 137 |
1 files changed, 84 insertions, 53 deletions
diff --git a/src/pvsgui.cpp b/src/pvsgui.cpp index 30ba4ed..0ed0801 100644 --- a/src/pvsgui.cpp +++ b/src/pvsgui.cpp @@ -17,6 +17,7 @@ # ----------------------------------------------------------------------------- */ +#include <getopt.h> #include "pvsgui.h" #include "version.h" @@ -122,8 +123,6 @@ PVSGUI::PVSGUI(QWidget *parent) : // show toolbar setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); setAttribute(Qt::WA_AlwaysShowToolTips); - updateConfig(); - hide(); } PVSGUI::~PVSGUI() @@ -137,9 +136,9 @@ PVSGUI::~PVSGUI() void PVSGUI::updateConfig() { if (_settings.value("Display/location").isNull()) - setLocation(POSITION_TOP_CENTER); + setPosition(POSITION_TOP_CENTER); else - setLocation(_settings.value("Display/location").toInt()); + setPosition(_settings.value("Display/location").toInt()); } @@ -149,6 +148,42 @@ void PVSGUI::setVisible(bool visible) _showAction->setChecked(isVisible()); } +void PVSGUI::setPosition(int position) +{ + _position = position; + switch (_position) + { + case POSITION_TOP_LEFT: + move(0, 0); + break; + case POSITION_TOP_CENTER: + move((QApplication::desktop()->width() - width()) / 2, 0); + break; + case POSITION_TOP_RIGHT: + move(QApplication::desktop()->width() - width(), 0); + break; + case POSITION_BOTTOM_LEFT: + move(0, QApplication::desktop()->height() - height()); + break; + case POSITION_BOTTOM_CENTER: + move((QApplication::desktop()->width() - width()) / 2, + QApplication::desktop()->height() - height()); + break; + case POSITION_BOTTOM_RIGHT: + move(QApplication::desktop()->width() - width(), + QApplication::desktop()->height() - height()); + break; + default: + updateConfig(); + } +} + +void PVSGUI::hide() +{ + if (!_menu->isVisible() && !_hostMenu->isVisible()) + hide(true); +} + //////////////////////////////////////////////////////////////////////////////// // Protected @@ -219,60 +254,24 @@ void PVSGUI::setupMenu() hostButton->setMenu(_hostMenu); } -void PVSGUI::setLocation(int location) -{ - _location = location; - switch (_location) - { - case POSITION_TOP_LEFT: - move(0, 0); - break; - case POSITION_TOP_CENTER: - move((QApplication::desktop()->width() - width()) / 2, 0); - break; - case POSITION_TOP_RIGHT: - move(QApplication::desktop()->width() - width(), 0); - break; - case POSITION_BOTTOM_LEFT: - move(0, QApplication::desktop()->height() - height()); - break; - case POSITION_BOTTOM_CENTER: - move((QApplication::desktop()->width() - width()) / 2, - QApplication::desktop()->height() - height()); - break; - case POSITION_BOTTOM_RIGHT: - move(QApplication::desktop()->width() - width(), - QApplication::desktop()->height() - height()); - break; - default: - break; - } -} - void PVSGUI::hide(bool b) { if (b) { - if (_location <= POSITION_TOP_RIGHT) + if (_position <= POSITION_TOP_RIGHT) move(x(), 2 - height()); else move(x(), QApplication::desktop()->height() - 2); } else { - if (_location <= POSITION_TOP_RIGHT) + if (_position <= POSITION_TOP_RIGHT) move(x(), 0); else move(x(), QApplication::desktop()->height() - height()); } } -void PVSGUI::hide() -{ - if (!_menu->isVisible() && !_hostMenu->isVisible()) - hide(true); -} - void PVSGUI::pvsConnect(QAction *action) { QString host = action->text(); @@ -424,9 +423,10 @@ void printHelp() qout << QObject::tr("Usage: pvsgui [OPTIONS]...") << endl; qout << QObject::tr("Start the Pool Video Switch GUI.") << endl; qout << QObject::tr("Options:") << endl << endl; - qout << "-n or --nobar" << "\t" << QObject::tr("Start only with systray icon.") << endl; - qout << "-h or --help" << "\t" << QObject::tr("Show this help text and quit.") << endl; - qout << "-v or --version" << "\t" << QObject::tr("Show version and quit.") << endl; + qout << "-b or --toolbar" << "\t\t" << QObject::tr("Start with toolbar.") << endl; + qout << "-p or --position" << "\t" << QObject::tr("Set toolbar position (0-5)") << endl; + qout << "-h or --help" << "\t\t" << QObject::tr("Show this help text and quit.") << endl; + qout << "-v or --version" << "\t\t" << QObject::tr("Show version and quit.") << endl; qout << endl; qout.flush(); exit(0); @@ -444,7 +444,6 @@ void printVersion() int main(int argc, char *argv[]) { QtSingleApplication app(argc, argv); - QStringList args = app.arguments(); app.setQuitOnLastWindowClosed(false); app.setOrganizationName("openslx"); app.setOrganizationDomain("openslx.org"); @@ -462,16 +461,48 @@ int main(int argc, char *argv[]) translator.load(":pvsgui"); app.installTranslator(&translator); - if (args.contains("-h") || args.contains("--help")) - printHelp(); + bool visible = false; + int position = -1; - if (args.contains("-v") || args.contains("--version")) - printVersion(); + // parse command line arguments + int opt = 0; + int longIndex = 0; + static const char *optString = "hvp:b?"; + static const struct option longOpts[] = + { + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, + { "position", required_argument, NULL, 'p' }, + { "toolbar", required_argument, NULL, 'b' } + }; + + opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); + while( opt != -1 ) + { + switch( opt ) + { + case 'h': + printHelp(); + break; + case 'v': + printVersion(); + break; + case 'p': + position = atoi(optarg); + break; + case 'b': + visible = true; + break; + case '?': + exit(1); + } + opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); + } PVSGUI pvsgui; - - if (!args.contains("-n") && !args.contains("--nobar")) - pvsgui.setVisible(true); + pvsgui.setPosition(position); + pvsgui.setVisible(visible); + pvsgui.hide(); return app.exec(); } |