-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various macOS UI improvements #6952
Conversation
I fixed the build issues except the one with qmake+gui. Your homebrew formula defines I could make it build even without the badges, but I see no reason to limit macOS functionality just because a certain toolchain is broken. |
src/CMakeLists.txt
Outdated
endif (GUI) | ||
if (DBUS) | ||
list (APPEND QBT_QT_COMPONENTS DBus) | ||
endif (DBUS) | ||
find_package(Qt5 5.5.1 COMPONENTS ${QBT_QT_COMPONENTS} REQUIRED) | ||
|
||
if (GUI AND APPLE) | ||
include_directories(${Qt5MacExtras_INCLUDE_DIRS}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one and the next 2 lines shall not be needed, as target_link_libraries(... Qt5::MacExtras)
, initiated by list (APPEND QBT_QT_COMPONENTS MacExtras)
call above should do the very same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this myself, but actually it does not work. If I remove these lines, compilation will stop working.
I could not explain the reason and simply hardcoded the variables. I think it is a bug in Qt, because I saw other people doing similar things on the net.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I forgot that when we migrated from Qt4, I replaced smart commands with direct component names. You have to mention Qt5::MacExtras in target_link_libraries() directly. For instance:
if (APPLE)
target_link_libraries(qbt_gui Qt5::MacExtras)
endif()
in src/gui/CMakeLists.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, thanks.
src/gui/mainwindow.cpp
Outdated
@@ -1929,7 +1929,7 @@ QIcon MainWindow::getSystrayIcon() const | |||
} | |||
|
|||
QIcon icon; | |||
#if (defined(Q_OS_UNIX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this fails the compilation?
src/app/main.cpp
Outdated
@@ -252,6 +252,11 @@ int main(int argc, char *argv[]) | |||
signal(SIGSEGV, sigAbnormalHandler); | |||
#endif | |||
|
|||
#ifdef Q_OS_MAC | |||
// On OS X the standard is to not show icons in the menus | |||
app->setAttribute(Qt::AA_DontShowIconsInMenus); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are already an #if defined(Q_OS_MAC)
block at line 210
you should move it there.
src/base/preferences.h
Outdated
@@ -115,16 +115,18 @@ class Preferences: public QObject | |||
void setHideZeroValues(bool b); | |||
int getHideZeroComboValues() const; | |||
void setHideZeroComboValues(int n); | |||
#ifndef Q_OS_MAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would take out all entries in this #ifndef
block and move it down to where you put
#ifndef Q_OS_MAC
TrayIcon::Style trayIconStyle() const;
src/gui/mainwindow.cpp
Outdated
@@ -52,6 +52,11 @@ | |||
#include <QCryptographicHash> | |||
#include <QProcess> | |||
|
|||
#ifdef Q_OS_MAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this block under
#include "mainwindow.h"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and move
#include <QtMac>
#include <QtMacExtras>
to here
src/gui/mainwindow.cpp
Outdated
@@ -204,6 +211,9 @@ MainWindow::MainWindow(QWidget *parent) | |||
qDebug("create tabWidget"); | |||
m_tabs = new HidableTabWidget(this); | |||
connect(m_tabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); | |||
#ifdef Q_OS_MAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this block 1 line up.
|
||
#ifdef Q_OS_MAC | ||
foreach (QAction *action, m_ui->toolBar->actions()) { | ||
if (action->isSeparator()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what its purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes vertical separators from the toolbar menu, they are invalid in macOS design. As I said above, there is no such concept. One could have space separation or no separation.
I replaced the separators with some extra space, but I think they are fine even if just removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, after searching for some osx toolbar screenshot on google, I get what you mean.
@@ -343,6 +367,7 @@ MainWindow::MainWindow(QWidget *parent) | |||
// Load Window state and sizes | |||
readSettings(); | |||
|
|||
#ifndef Q_OS_MAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this equivalent?
if (!m_systrayIcon) {
// Make sure the Window is visible if we don't have a tray icon
if (pref->startMinimized()) {
showMinimized();
}
else {
show();
activateWindow();
raise();
}
}
#ifndef Q_OS_MAC
else {
if (!(pref->startMinimized() || m_uiLocked)) {
show();
activateWindow();
raise();
}
else if (pref->startMinimized()) {
showMinimized();
if (pref->minimizeToTray())
hide();
}
}
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_systrayIcon is undefined on mac, so one cannot write it this way.
src/gui/mainwindow.cpp
Outdated
@@ -1022,12 +1055,20 @@ void MainWindow::showEvent(QShowEvent *e) | |||
void MainWindow::closeEvent(QCloseEvent *e) | |||
{ | |||
Preferences *const pref = Preferences::instance(); | |||
#ifndef Q_OS_MAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change it to #ifdef Q_OS_MAC
and switch the code
src/gui/mainwindow.cpp
Outdated
m_systrayIcon->setToolTip(html); // tray icon | ||
} | ||
#else | ||
if (status.payloadDownloadRate > 0) | ||
QtMac::setBadgeLabelText(tr("%1/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change tr
to QString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is a correct suggestion? E.g. in Russian I would want to see %1/с not s. Since seconds in Russian are секунды
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is a correct suggestion?
After reading your explanation, obviously not.
IMO, it would be better to add this:
QtMac::setBadgeLabelText(tr("%1/s", "s is shorthand for seconds")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate)));
and split the line please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, done
src/gui/mainwindow.h
Outdated
void balloonClicked(); | ||
void writeSettings(); | ||
void readSettings(); | ||
#ifndef Q_OS_MAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this block down to under void toolbarFollowSystem();
src/gui/optionsdlg.cpp
Outdated
@@ -143,13 +143,17 @@ OptionsDialog::OptionsDialog(QWidget *parent) | |||
|
|||
// Load options | |||
loadOptions(); | |||
#ifndef Q_OS_MAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write #ifdef Q_OS_MAC
and switch code.
2 things I wanted to add:
|
src/gui/mainwindow.cpp
Outdated
Class cls = objc_getClass("NSApplication"); | ||
objc_object *appInst = objc_msgSend(reinterpret_cast<objc_object *>(cls), sel_registerName("sharedApplication")); | ||
|
||
if (appInst != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!appInst)
return;
dockMainWindowHandle = this;
// and so on...
src/gui/mainwindow.cpp
Outdated
|
||
static MainWindow *dockMainWindowHandle; | ||
|
||
static bool dockClickHandler(id self, SEL _cmd, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move {
to a newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls avoid using underscore in variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls avoid using underscore in variable names.
@vit9696
I think you missed this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, actually did. Fixed it now.
src/gui/mainwindow.cpp
Outdated
return false; | ||
} | ||
|
||
void MainWindow::setupDockClickHandler() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move { to a newline.
src/gui/categoryfilterwidget.cpp
Outdated
@@ -73,6 +73,7 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent) | |||
setIconSize(Utils::Misc::smallIconSize()); | |||
#if defined(Q_OS_MAC) | |||
setAttribute(Qt::WA_MacShowFocusRect, false); | |||
setIndentation(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it's any different in mac but in KDE if you do this and enable Use Subcategories
in options, any subcategories vanish from the sidepanel and there doesn't seem to be a way to show them because the expand icon isn't visible.
I realize this is probably out of the scope of this PR, IMO this should be used on all platforms but only when Use Subcategories
is disabled and maybe reduce the indentation of branches (and the root as much as possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thalieht actually I faield to find this option yesterday, and thus assumed that subcategories simply do not work on macOS. Now I found it, thanks :)
I changed the indentation to not be disabled when they are off, but doing something like this for all the platforms is the job of a separate pull request indeed.
@Chocobo1 I fixed all the issues you asked me to change except the ones I consider invalid. |
src/gui/categoryfilterwidget.cpp
Outdated
@@ -73,6 +73,8 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent) | |||
setIconSize(Utils::Misc::smallIconSize()); | |||
#if defined(Q_OS_MAC) | |||
setAttribute(Qt::WA_MacShowFocusRect, false); | |||
if (!BitTorrent::Session::instance()->isSubcategoriesEnabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if Use Subcategories
is changed it would need a restart for the indentation to change. Is that ok?
If you can make it change without restart i would like to suggest to move this out of the #if
so all platforms can have it.
Edit: On second thought moving it outside the #if
wouldn't fit the PR name :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course I could fix it, and I have just done it. Thanks for reminding. But you are right, if I change it outside the preprocessor macro, it wouldn't fit this PR.
I have no development tools installed for the other platforms, but I think it should work fine for them. You or anybody else could submit a new PR removing the ifdefs once this gets merged :)
src/gui/categoryfilterwidget.h
Outdated
@@ -57,4 +57,8 @@ private slots: | |||
QSize minimumSizeHint() const override; | |||
void rowsInserted(const QModelIndex &parent, int start, int end) override; | |||
QString askCategoryName(); | |||
|
|||
#ifdef Q_OS_MAC | |||
int defaultIndentation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private variables should prepended with m_
,
thus m_defaultIndentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Alright, I squashed all the changes into a single commit and even fixed a couple of other issues I spotted. Would you please merge this? |
src/app/main.cpp
Outdated
QByteArray path = "/usr/local/bin:"; | ||
path += qgetenv("PATH"); | ||
qputenv("PATH", path.constData()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do us a favor if you don't mind: remove the curly braces here, it isn't really needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
I would like to if I can verify this PR on a mac, otherwise, this PR will be handled by the project owner @sledgehammer999. |
@Chocobo1 well, I build this on a vm (too much of a dislike for Qt to let it arrive on my real machines), and can give you vnc or teamviewer without any issues. Maybe you could spot something yourself… |
@LordNyriox actually it is a very small change, so I added it right here. To be honest, after this I felt like making all the icons greyscale on macOS and be done with it. I am not sure how to do it properly. On macOS one pretty much must use greyscale icons on toolbar, statusbar, in fact everywhere. And what you have at the moment looks terrible. Shall I open an issue for a discussion? You have some theming pull requests here awaiting the merge, but this is not really about theming but about following the mandatory UI guidelines. |
And just another thing, while I was changing the Preferences title I thought that something is wrong with the window. Now I see it. You use a qBittorrent icon everywhere in the windows. On macOS we do not have a window icon unless this icon represents a file type, which is quite convenient. Also fixed everywhere. |
Thx for the time you took to find all the little details and fix them. |
Getting some errors on qbt launch: $ src/qbittorrent
QObject::connect: No such slot MainWindow::toggleVisibility()
QObject::connect: (sender name: 'actionToggleVisibility')
QObject::connect: (receiver name: 'MainWindow')
QObject::connect: No such slot MainWindow::updateTrayIconMenu()
QObject::connect: (receiver name: 'MainWindow')
QObject::connect: No such slot MainWindow::toggleVisibility(QSystemTrayIcon::ActivationReason)
QObject::connect: (receiver name: 'MainWindow') |
@Chocobo1 I definitely don't have this. The only issues I see are:
And they are most certainly due to #6156. |
Oh, I see, thanks a lot :) |
if (GUI AND APPLE) | ||
# Fix MOC inability to detect macOS. This seems to only affect cmake. | ||
# Relevant issue: https://bugreports.qt.io/browse/QTBUG-58325 | ||
set(CMAKE_AUTOMOC_MOC_OPTIONS ${CMAKE_AUTOMOC_MOC_OPTIONS} -DQ_OS_MAC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vit9696, could you test CMake 3.9 and without this define, please? As of version 3.9 CMake generates moc_predefs.h
as qmake does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, exactly the same error. Find reveals no such file moc_predefs.h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. The results is quite unexpected.
Hello. I'm relatively new. I love qBittorrent. I'd like to see ETA (expected time to finish download) on the Badge instead of Global Download Speed, as it makes sense to me, to not to check now and then from the window and then hide it again. I know C++ but not Qt. |
Hello,
This pull-request consolidates and fixes most of the existing changes (e.g. #4757 and #2096) and brings us other improvements. Whereas this is not a complete fix to all design issues in qBittorrent in regards to macOS, this is certainly a good start.
Please let me know what you consider important to change (if anything), and let's get this merged :)
The changelist includes:
Screenshots
Regarding separator → spacer replacement: I am thinking of removing them entirely, since they do not really add much clarity, but to my eyes it looks fine either way. If you think it is better to remove them, let me know.
Regarding Dock restoration: it is a very annoying bug (or shall I say feature) in Qt, no event is delivered to the dispatcher when you click on the icon regardless of the docs. The only reason is to use native APIs, and although it is a little ugly, it works well.
Regarding the badges: the API Qt offers is very limited, and one cannot display more than a single line, and its length is very short. To avoid dotted shortening even the "D: " prefix was removed. Unfortunately it also does not allow colouring, and to avoid different sorts of confusion I decided not to add the uploading speed badge.
Even though I am open for a discussion on what is worth changing and may even make another pull-request fixing certain other areas, I will not add any new features to the current one.
Among the macOS-specific issues I am aware of are all the menu/app icons. They are supposed to be greyscale, not coloured. And I am actually wondering how would you prefer to change it?