Browse Source

Add a context menu to the toolbar to change the position of the text

Closes #1145.
adaptive-webui-19844
Gabriele 10 years ago
parent
commit
0ebfea6c68
  1. 94
      src/mainwindow.cpp
  2. 8
      src/mainwindow.h
  3. 8
      src/preferences/preferences.cpp
  4. 2
      src/preferences/preferences.h

94
src/mainwindow.cpp

@ -124,6 +124,8 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine): QMai
#endif #endif
setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png"))); setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png")));
addToolbarContextMenu();
actionOpen->setIcon(IconProvider::instance()->getIcon("list-add")); actionOpen->setIcon(IconProvider::instance()->getIcon("list-add"));
actionDownload_from_URL->setIcon(IconProvider::instance()->getIcon("insert-link")); actionDownload_from_URL->setIcon(IconProvider::instance()->getIcon("insert-link"));
actionSet_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))); actionSet_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png")));
@ -356,6 +358,97 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine): QMai
} }
} }
void MainWindow::addToolbarContextMenu()
{
const Preferences* const pref = Preferences::instance();
toolbarMenu = new QMenu(this);
toolBar->setContextMenuPolicy(Qt::CustomContextMenu);
connect(toolBar, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(toolbarMenuRequested(QPoint)));
QAction *iconsOnly = new QAction(tr("Icons Only"), toolbarMenu);
connect(iconsOnly, SIGNAL(triggered()), this, SLOT(toolbarIconsOnly()));
QAction *textOnly = new QAction(tr("Text Only"), toolbarMenu);
connect(textOnly, SIGNAL(triggered()), this, SLOT(toolbarTextOnly()));
QAction *textBesideIcons = new QAction(tr("Text Alongside Icons"), toolbarMenu);
connect(textBesideIcons, SIGNAL(triggered()), this, SLOT(toolbarTextBeside()));
QAction *textUnderIcons = new QAction(tr("Text Under Icons"), toolbarMenu);
connect(textUnderIcons, SIGNAL(triggered()), this, SLOT(toolbarTextUnder()));
QAction *followSystemStyle = new QAction(tr("Follow System Style"), toolbarMenu);
connect(followSystemStyle, SIGNAL(triggered()), this, SLOT(toolbarFollowSystem()));
toolbarMenu->addAction(iconsOnly);
toolbarMenu->addAction(textOnly);
toolbarMenu->addAction(textBesideIcons);
toolbarMenu->addAction(textUnderIcons);
toolbarMenu->addAction(followSystemStyle);
QActionGroup *textPositionGroup = new QActionGroup(toolbarMenu);
textPositionGroup->addAction(iconsOnly);
iconsOnly->setCheckable(true);
textPositionGroup->addAction(textOnly);
textOnly->setCheckable(true);
textPositionGroup->addAction(textBesideIcons);
textBesideIcons->setCheckable(true);
textPositionGroup->addAction(textUnderIcons);
textUnderIcons->setCheckable(true);
textPositionGroup->addAction(followSystemStyle);
followSystemStyle->setCheckable(true);
const Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(pref->getToolbarTextPosition());
if (buttonStyle >= Qt::ToolButtonIconOnly && buttonStyle <= Qt::ToolButtonFollowStyle)
toolBar->setToolButtonStyle(buttonStyle);
switch (buttonStyle) {
case Qt::ToolButtonIconOnly:
iconsOnly->setChecked(true);
break;
case Qt::ToolButtonTextOnly:
textOnly->setChecked(true);
break;
case Qt::ToolButtonTextBesideIcon:
textBesideIcons->setChecked(true);
break;
case Qt::ToolButtonTextUnderIcon:
textUnderIcons->setChecked(true);
break;
default:
followSystemStyle->setChecked(true);
}
}
void MainWindow::toolbarMenuRequested(QPoint point)
{
toolbarMenu->exec(toolBar->mapToGlobal(point));
}
void MainWindow::toolbarIconsOnly()
{
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonIconOnly);
}
void MainWindow::toolbarTextOnly()
{
toolBar->setToolButtonStyle(Qt::ToolButtonTextOnly);
Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonTextOnly);
}
void MainWindow::toolbarTextBeside()
{
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonTextBesideIcon);
}
void MainWindow::toolbarTextUnder()
{
toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonTextUnderIcon);
}
void MainWindow::toolbarFollowSystem()
{
toolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonFollowStyle);
}
void MainWindow::shutdownCleanUp() void MainWindow::shutdownCleanUp()
{ {
qDebug("GUI destruction"); qDebug("GUI destruction");
@ -410,6 +503,7 @@ void MainWindow::shutdownCleanUp()
delete switchSearchShortcut2; delete switchSearchShortcut2;
delete switchTransferShortcut; delete switchTransferShortcut;
delete switchRSSShortcut; delete switchRSSShortcut;
delete toolbarMenu;
IconProvider::drop(); IconProvider::drop();
Preferences::drop(); Preferences::drop();
qDebug("Finished GUI destruction"); qDebug("Finished GUI destruction");

8
src/mainwindow.h

@ -161,6 +161,7 @@ private slots:
void pythonDownloadSuccess(QString url, QString file_path); void pythonDownloadSuccess(QString url, QString file_path);
void pythonDownloadFailure(QString url, QString error); void pythonDownloadFailure(QString url, QString error);
#endif #endif
void addToolbarContextMenu();
private: private:
QFileSystemWatcher *executable_watcher; QFileSystemWatcher *executable_watcher;
@ -214,6 +215,7 @@ private:
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
bool has_python; bool has_python;
#endif #endif
QMenu* toolbarMenu;
private slots: private slots:
void on_actionSearch_engine_triggered(); void on_actionSearch_engine_triggered();
@ -232,6 +234,12 @@ private slots:
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
void checkProgramUpdate(); void checkProgramUpdate();
#endif #endif
void toolbarMenuRequested(QPoint);
void toolbarIconsOnly();
void toolbarTextOnly();
void toolbarTextBeside();
void toolbarTextUnder();
void toolbarFollowSystem();
}; };
#endif #endif

8
src/preferences/preferences.cpp

@ -1952,6 +1952,14 @@ void Preferences::setRssFeedsAliases(const QStringList &rssAliases) {
setValue("Rss/streamAlias", rssAliases); setValue("Rss/streamAlias", rssAliases);
} }
int Preferences::getToolbarTextPosition() const {
return value("Toolbar/textPosition", -1).toInt();
}
void Preferences::setToolbarTextPosition(const int position) {
setValue("Toolbar/textPosition", position);
}
QList<QByteArray> Preferences::getHostNameCookies(const QString &host_name) const { QList<QByteArray> Preferences::getHostNameCookies(const QString &host_name) const {
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap(); QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
if (!hosts_table.contains(host_name)) return QList<QByteArray>(); if (!hosts_table.contains(host_name)) return QList<QByteArray>();

2
src/preferences/preferences.h

@ -460,6 +460,8 @@ public:
void setTransSelFilter(const int &index); void setTransSelFilter(const int &index);
QByteArray getTransHeaderState() const; QByteArray getTransHeaderState() const;
void setTransHeaderState(const QByteArray &state); void setTransHeaderState(const QByteArray &state);
int getToolbarTextPosition() const;
void setToolbarTextPosition(const int position);
// Temp code. // Temp code.
// See TorrentStatistics::loadStats() for details. // See TorrentStatistics::loadStats() for details.

Loading…
Cancel
Save