Skip to content
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

Merged
merged 1 commit into from
Jul 15, 2017
Merged

Various macOS UI improvements #6952

merged 1 commit into from
Jul 15, 2017

Conversation

vit9696
Copy link
Contributor

@vit9696 vit9696 commented Jun 12, 2017

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

before
after

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?

@vit9696
Copy link
Contributor Author

vit9696 commented Jun 12, 2017

I fixed the build issues except the one with qmake+gui. Your homebrew formula defines -skip qtmacextras, which is necessary to provide Dock icon badges and thus mandatory. Once you update your toolchain (just removing this line should be enough), your buildsystem will start working once again.

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.

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})
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks.

@@ -1929,7 +1929,7 @@ QIcon MainWindow::getSystrayIcon() const
}

QIcon icon;
#if (defined(Q_OS_UNIX)
Copy link
Member

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);
Copy link
Member

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.

@@ -115,16 +115,18 @@ class Preferences: public QObject
void setHideZeroValues(bool b);
int getHideZeroComboValues() const;
void setHideZeroComboValues(int n);
#ifndef Q_OS_MAC
Copy link
Member

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;

@@ -52,6 +52,11 @@
#include <QCryptographicHash>
#include <QProcess>

#ifdef Q_OS_MAC
Copy link
Member

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"

Copy link
Member

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

@@ -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
Copy link
Member

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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what its purpose?

Copy link
Contributor Author

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.

Copy link
Member

@Chocobo1 Chocobo1 Jun 12, 2017

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
Copy link
Member

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

Copy link
Contributor Author

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.

@@ -1022,12 +1055,20 @@ void MainWindow::showEvent(QShowEvent *e)
void MainWindow::closeEvent(QCloseEvent *e)
{
Preferences *const pref = Preferences::instance();
#ifndef Q_OS_MAC
Copy link
Member

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

m_systrayIcon->setToolTip(html); // tray icon
}
#else
if (status.payloadDownloadRate > 0)
QtMac::setBadgeLabelText(tr("%1/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change tr to QString

Copy link
Contributor Author

@vit9696 vit9696 Jun 12, 2017

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 секунды.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, done

void balloonClicked();
void writeSettings();
void readSettings();
#ifndef Q_OS_MAC
Copy link
Member

@Chocobo1 Chocobo1 Jun 12, 2017

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();

@@ -143,13 +143,17 @@ OptionsDialog::OptionsDialog(QWidget *parent)

// Load options
loadOptions();
#ifndef Q_OS_MAC
Copy link
Member

@Chocobo1 Chocobo1 Jun 12, 2017

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.

@Chocobo1
Copy link
Member

2 things I wanted to add:

  1. create fixup commits for now, note that eventually you'll have to squash all commits into one.
  2. please provide before & after screenshots if possible, majority (at least me) of the devs don't have easy access to a mac.

Class cls = objc_getClass("NSApplication");
objc_object *appInst = objc_msgSend(reinterpret_cast<objc_object *>(cls), sel_registerName("sharedApplication"));

if (appInst != nullptr) {
Copy link
Member

@Chocobo1 Chocobo1 Jun 12, 2017

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...


static MainWindow *dockMainWindowHandle;

static bool dockClickHandler(id self, SEL _cmd, ...) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move { to a newline.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

return false;
}

void MainWindow::setupDockClickHandler() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move { to a newline.

@@ -73,6 +73,7 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent)
setIconSize(Utils::Misc::smallIconSize());
#if defined(Q_OS_MAC)
setAttribute(Qt::WA_MacShowFocusRect, false);
setIndentation(0);
Copy link
Contributor

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).

Copy link
Contributor Author

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.

@vit9696
Copy link
Contributor Author

vit9696 commented Jun 12, 2017

@Chocobo1 I fixed all the issues you asked me to change except the ones I consider invalid.
The screenshots are available in the first post if you did not notice ^^

@@ -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())
Copy link
Contributor

@thalieht thalieht Jun 12, 2017

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 :)

Copy link
Contributor Author

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 :)

@@ -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;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@vit9696 vit9696 closed this Jun 12, 2017
@vit9696 vit9696 reopened this Jun 12, 2017
@vit9696
Copy link
Contributor Author

vit9696 commented Jun 12, 2017

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());
}
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@Chocobo1
Copy link
Member

Chocobo1 commented Jun 13, 2017

Would you please merge this?

I would like to if I can verify this PR on a mac, otherwise, this PR will be handled by the project owner @sledgehammer999.

@vit9696
Copy link
Contributor Author

vit9696 commented Jun 13, 2017

@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…
Ping me on irc or write an email to vit9696 at avp dot su.

@vit9696
Copy link
Contributor Author

vit9696 commented Jun 13, 2017

@LordNyriox actually it is a very small change, so I added it right here.
It is especially bad because of the main menus, where the entry already says "Preferences…", and because of Dock that has Options.

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.

@vit9696
Copy link
Contributor Author

vit9696 commented Jun 13, 2017

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.

@vit9696
Copy link
Contributor Author

vit9696 commented Jun 13, 2017

In addition to the screens in the first post, here are more:

Screenshots

screen shot 2017-06-13 at 02 30 40
screen shot 2017-06-13 at 02 30 48
screen shot 2017-06-13 at 02 31 03
screen shot 2017-06-13 at 02 32 18
screen shot 2017-06-13 at 02 32 28
screen shot 2017-06-13 at 02 33 43

@sledgehammer999
Copy link
Member

Thx for the time you took to find all the little details and fix them.

@sledgehammer999 sledgehammer999 merged commit c964f0c into qbittorrent:master Jul 15, 2017
@LordNyriox LordNyriox mentioned this pull request Jul 15, 2017
12 tasks
@Chocobo1
Copy link
Member

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')

@vit9696
Copy link
Contributor Author

vit9696 commented Jul 16, 2017

@Chocobo1 I definitely don't have this. The only issues I see are:

$ /Applications/qbittorrent.app/Contents/MacOS/qbittorrent ; exit; 
2017-07-16 12:46:45.118 qbittorrent[34665:31468133] Path  given to -[NSWorkspace iconForFile:] is not a full path.
2017-07-16 12:46:45.118 qbittorrent[34665:31468133] Path  given to -[NSWorkspace iconForFile:] is not a full path.

And they are most certainly due to #6156.
Are you using cmake or qmake builds? I use cmake, and now I do wonder whether qmake also needs Q_OS_MAC definition for MOC. Like this one.

@Chocobo1
Copy link
Member

@vit9696
No worries, #7106 has just been merged.

Are you using cmake or qmake builds?

qmake

@vit9696
Copy link
Contributor Author

vit9696 commented Jul 16, 2017

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@D3V4N5H
Copy link

D3V4N5H commented Jul 26, 2018

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.
How can I contribute?
Do I need any special development environment in my MacBook Air?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS: macOS Issues specific to macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants