From: Flavio Date: Wed, 9 Jan 2013 20:46:54 +0000 (+0100) Subject: Ambiance integration X-Git-Tag: 2.0~34 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=32e93088f8cb5c4f56e142a08681c4d18ddc378f;p=minitube Ambiance integration --- diff --git a/src/main.cpp b/src/main.cpp index 05d1e3b..3804183 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,53 @@ #include "mac_startup.h" #endif +#ifdef Q_WS_X11 +QString getThemeName() { + QString themeName; + + QProcess process; + process.start("dconf", + QStringList() << "read" << "/org/gnome/desktop/interface/gtk-theme"); + if (process.waitForFinished()) { + themeName = process.readAllStandardOutput(); + themeName = themeName.trimmed(); + themeName.remove('\''); + if (!themeName.isEmpty()) return themeName; + } + + QString rcPaths = QString::fromLocal8Bit(qgetenv("GTK2_RC_FILES")); + if (!rcPaths.isEmpty()) { + QStringList paths = rcPaths.split(QLatin1String(":")); + foreach (const QString &rcPath, paths) { + if (!rcPath.isEmpty()) { + QFile rcFile(rcPath); + if (rcFile.exists() && rcFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&rcFile); + while(!in.atEnd()) { + QString line = in.readLine(); + if (line.contains(QLatin1String("gtk-theme-name"))) { + line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1); + line.remove(QLatin1Char('\"')); + line = line.trimmed(); + themeName = line; + break; + } + } + } + } + if (!themeName.isEmpty()) + break; + } + } + + // Fall back to gconf + if (themeName.isEmpty()) + themeName = QGtkStyle::getGConfString(QLatin1String("/desktop/gnome/interface/gtk_theme")); + + return themeName; +} +#endif + int main(int argc, char **argv) { #ifdef Q_WS_MAC @@ -29,14 +76,18 @@ int main(int argc, char **argv) { app.setApplicationName(Constants::NAME); app.setOrganizationName(Constants::ORG_NAME); app.setOrganizationDomain(Constants::ORG_DOMAIN); -#ifndef APP_WIN app.setWheelScrollLines(1); -#endif app.setAttribute(Qt::AA_DontShowIconsInMenus); #ifndef Q_WS_X11 Extra::appSetup(&app); #else + bool isGtk = app.style()->metaObject()->className() == QLatin1String("QGtkStyle"); + if (isGtk) { + app.setProperty("gtk", isGtk); + QString themeName = getThemeName(); + app.setProperty("style", themeName); + } QFile cssFile(":/style.css"); cssFile.open(QFile::ReadOnly); QString styleSheet = QLatin1String(cssFile.readAll()); @@ -70,6 +121,8 @@ int main(int argc, char **argv) { #ifndef Q_WS_X11 Extra::windowSetup(&mainWin); +#else + mainWin.setProperty("style", app.property("style")); #endif // no window icon on Mac @@ -92,8 +145,6 @@ int main(int argc, char **argv) { mainWin.setWindowIcon(appIcon); #endif - mainWin.show(); - mainWin.connect(&app, SIGNAL(messageReceived(const QString &)), &mainWin, SLOT(messageReceived(const QString &))); app.setActivationWindow(&mainWin, true); @@ -112,6 +163,8 @@ int main(int argc, char **argv) { } } + mainWin.show(); + // Seed random number generator qsrand(QDateTime::currentDateTime().toTime_t()); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a1c5991..dda3622 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -66,7 +66,9 @@ MainWindow::MainWindow() : // views mechanism history = new QStack(); - views = new QStackedWidget(this); + views = new QStackedWidget(); + views->hide(); + setCentralWidget(views); // views homeView = new HomeView(this); @@ -115,7 +117,7 @@ MainWindow::MainWindow() : showActivationView(false); #endif - setCentralWidget(views); + views->show(); // Global shortcuts GlobalShortcuts &shortcuts = GlobalShortcuts::instance(); @@ -409,7 +411,7 @@ void MainWindow::createActions() { action->setStatusTip(tr("Show details about video downloads")); action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J)); action->setCheckable(true); - action->setIcon(Utils::icon("go-down")); + action->setIcon(Utils::icon("document-save")); action->setVisible(false); connect(action, SIGNAL(toggled(bool)), SLOT(toggleDownloads(bool))); actions->insert("downloads", action); @@ -419,7 +421,7 @@ void MainWindow::createActions() { #ifndef APP_NO_DOWNLOADS action->setShortcut(QKeySequence::Save); #endif - action->setIcon(Utils::icon("go-down")); + action->setIcon(Utils::icon("document-save")); action->setEnabled(false); #if QT_VERSION >= 0x040600 action->setPriority(QAction::LowPriority); @@ -497,7 +499,7 @@ void MainWindow::createActions() { action = new QAction(tr("More..."), this); actions->insert("more-region", action); - action = new QAction(Utils::icon("related-videos"), tr("&Related Videos"), this); + action = new QAction(Utils::icon(QStringList() << "view-list" << "format-justify-fill"), tr("&Related Videos"), this); action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); action->setStatusTip(tr("Watch videos related to the current one")); action->setEnabled(false); @@ -619,11 +621,7 @@ void MainWindow::createToolBars() { setUnifiedTitleAndToolBarOnMac(true); mainToolBar = new QToolBar(this); -#if QT_VERSION < 0x040600 | defined(APP_MAC) mainToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly); -#else - mainToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle); -#endif mainToolBar->setFloatable(false); mainToolBar->setMovable(false); @@ -634,7 +632,11 @@ void MainWindow::createToolBars() { mainToolBar->addAction(stopAct); mainToolBar->addAction(pauseAct); mainToolBar->addAction(skipAct); + mainToolBar->addAction(The::globalActions()->value("related-videos")); +#ifndef APP_NO_DOWNLOADS + mainToolBar->addAction(The::globalActions()->value("download")); +#endif bool addFullScreenAct = true; #ifdef Q_WS_MAC @@ -642,10 +644,6 @@ void MainWindow::createToolBars() { #endif if (addFullScreenAct) mainToolBar->addAction(fullscreenAct); -#ifndef APP_NO_DOWNLOADS - mainToolBar->addAction(The::globalActions()->value("download")); -#endif - mainToolBar->addWidget(new Spacer()); QFont smallerFont = FontUtils::small(); @@ -723,7 +721,6 @@ void MainWindow::createStatusBar() { regionButton = new QToolButton(this); regionButton->setStatusTip(tr("Choose your content location")); - regionButton->setIcon(Utils::icon("go-down")); regionButton->setIconSize(QSize(16, 16)); regionButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); regionAction = statusToolBar->addWidget(regionButton); diff --git a/src/utils.cpp b/src/utils.cpp index 19a9a4a..3973a6b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -3,10 +3,30 @@ #include "extra.h" #endif -QIcon Utils::icon(const QString &name) { +QIcon getIcon(const QString &name) { #ifdef Q_WS_X11 return QIcon::fromTheme(name); #else return Extra::getIcon(name); #endif } + +QIcon Utils::icon(const QString &name) { +#ifdef Q_WS_X11 + QString themeName = qApp->property("style").toString(); + if (themeName == "Ambiance") + return icon(QStringList() << name + "-symbolic" << name); + else return getIcon(name); +#else + return Extra::getIcon(name); +#endif +} + +QIcon Utils::icon(const QStringList &names) { + QIcon icon; + foreach (QString name, names) { + icon = getIcon(name); + if (!icon.availableSizes().isEmpty()) break; + } + return icon; +} diff --git a/src/utils.h b/src/utils.h index af3115b..1b023e8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,12 +1,13 @@ #ifndef UTILS_H #define UTILS_H -#include +#include class Utils { public: static QIcon icon(const QString &name); + static QIcon icon(const QStringList &names); private: Utils() { } diff --git a/style.css b/style.css index 3f6c9e4..0232aa2 100644 --- a/style.css +++ b/style.css @@ -33,10 +33,10 @@ RegionsView QPushButton[regionId]:checked { SidebarHeader { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #262626, stop: 1 #3c3c3c); - border: 0; padding: 0; margin: 0; spacing: 0; + border-bottom: 1px solid black; } SidebarHeader QToolButton { @@ -58,3 +58,55 @@ SidebarHeader QComboBox::drop-down { width: 0; border-style: none; } + +/* Ambiance */ + +MainWindow[style="Ambiance"] > QToolBar { + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, + stop: 0 #3c3b37, stop: 1 #474641); + border-top: 1px solid #474641; +} + +MainWindow[style="Ambiance"] > QToolBar QLabel { + color: #dfdbd2; +} + +MainWindow[style="Ambiance"] QSlider::groove:horizontal { + border: 1px solid #808080; + height: 8px; + background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #ccc); + border-radius: 5px; +} + +MainWindow[style="Ambiance"] QSlider::sub-page:horizontal { + border: 1px solid #808080; + height: 8px; + background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #6c6c6c, stop:1 #B1B1B1); + border-radius: 5px; +} + +MainWindow[style="Ambiance"] QSlider::handle:horizontal { + border: 1px solid #5c5c5c; + width: 14px; + height: 16px; + margin: -4px 0; + border-radius: 8px; + background: qradialgradient( + cx: .5, cy: .5, + fx: .33, fy: .33, + radius: .5, + stop: 0 #fff, stop: 1 #ccc); +} + +MainWindow[style="Ambiance"] QSlider::handle:pressed { + background: qradialgradient( + cx: .5, cy: .5, + fx: .33, fy: .33, + radius: .5, + stop: 0 #ccc, stop: 1 #9c9c9c); +} + +MainWindow[style="Ambiance"] Phonon--SeekSlider QSlider::sub-page:horizontal { + border: 1px solid #808080; + background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #6c6c6c); +}