Eliminate the need of Q_OBJECT in main_window_linux and main_window_win

This commit is contained in:
Ilya Fedin 2020-08-28 20:14:19 +04:00 committed by John Preston
parent 612e0d4a10
commit 3c8c059447
5 changed files with 69 additions and 67 deletions

View File

@ -764,7 +764,9 @@ void MainWindow::handleTrayIconActication(
}
if (reason == QSystemTrayIcon::Context) {
updateTrayMenu(true);
QTimer::singleShot(1, this, SLOT(psShowTrayMenu()));
base::call_delayed(1, this, [=] {
psShowTrayMenu();
});
} else if (!skipTrayClick()) {
if (Platform::IsWayland() ? isVisible() : isActive()) {
minimizeToTray();

View File

@ -435,7 +435,12 @@ void MainWindow::initHook() {
sniWatcher,
&QDBusServiceWatcher::serviceOwnerChanged,
this,
&MainWindow::onSNIOwnerChanged);
[=](
const QString &service,
const QString &oldOwner,
const QString &newOwner) {
handleSNIOwnerChanged(service, oldOwner, newOwner);
});
AppMenuSupported = IsAppMenuSupported();
@ -449,13 +454,18 @@ void MainWindow::initHook() {
appMenuWatcher,
&QDBusServiceWatcher::serviceOwnerChanged,
this,
&MainWindow::onAppMenuOwnerChanged);
[=](
const QString &service,
const QString &oldOwner,
const QString &newOwner) {
handleAppMenuOwnerChanged(service, oldOwner, newOwner);
});
connect(
windowHandle(),
&QWindow::visibleChanged,
this,
&MainWindow::onVisibleChanged);
[=](bool visible) { handleVisibleChanged(visible); });
if (AppMenuSupported) {
LOG(("Using D-Bus global menu."));
@ -560,7 +570,7 @@ void MainWindow::attachToSNITrayIcon() {
updateTrayMenu();
}
void MainWindow::onSNIOwnerChanged(
void MainWindow::handleSNIOwnerChanged(
const QString &service,
const QString &oldOwner,
const QString &newOwner) {
@ -596,7 +606,7 @@ void MainWindow::onSNIOwnerChanged(
}
}
void MainWindow::onAppMenuOwnerChanged(
void MainWindow::handleAppMenuOwnerChanged(
const QString &service,
const QString &oldOwner,
const QString &newOwner) {
@ -780,7 +790,7 @@ void MainWindow::createGlobalMenu() {
auto quit = file->addAction(
tr::lng_mac_menu_quit_telegram(tr::now, lt_telegram, qsl("Telegram")),
App::wnd(),
SLOT(quitFromTray()),
[=] { App::wnd()->quitFromTray(); },
QKeySequence::Quit);
quit->setMenuRole(QAction::QuitRole);
@ -790,13 +800,13 @@ void MainWindow::createGlobalMenu() {
psUndo = edit->addAction(
tr::lng_linux_menu_undo(tr::now),
this,
SLOT(psLinuxUndo()),
[=] { psLinuxUndo(); },
QKeySequence::Undo);
psRedo = edit->addAction(
tr::lng_linux_menu_redo(tr::now),
this,
SLOT(psLinuxRedo()),
[=] { psLinuxRedo(); },
QKeySequence::Redo);
edit->addSeparator();
@ -804,24 +814,24 @@ void MainWindow::createGlobalMenu() {
psCut = edit->addAction(
tr::lng_mac_menu_cut(tr::now),
this,
SLOT(psLinuxCut()),
[=] { psLinuxCut(); },
QKeySequence::Cut);
psCopy = edit->addAction(
tr::lng_mac_menu_copy(tr::now),
this,
SLOT(psLinuxCopy()),
[=] { psLinuxCopy(); },
QKeySequence::Copy);
psPaste = edit->addAction(
tr::lng_mac_menu_paste(tr::now),
this,
SLOT(psLinuxPaste()),
[=] { psLinuxPaste(); },
QKeySequence::Paste);
psDelete = edit->addAction(
tr::lng_mac_menu_delete(tr::now),
this,
SLOT(psLinuxDelete()),
[=] { psLinuxDelete(); },
QKeySequence(Qt::ControlModifier | Qt::Key_Backspace));
edit->addSeparator();
@ -829,44 +839,44 @@ void MainWindow::createGlobalMenu() {
psBold = edit->addAction(
tr::lng_menu_formatting_bold(tr::now),
this,
SLOT(psLinuxBold()),
[=] { psLinuxBold(); },
QKeySequence::Bold);
psItalic = edit->addAction(
tr::lng_menu_formatting_italic(tr::now),
this,
SLOT(psLinuxItalic()),
[=] { psLinuxItalic(); },
QKeySequence::Italic);
psUnderline = edit->addAction(
tr::lng_menu_formatting_underline(tr::now),
this,
SLOT(psLinuxUnderline()),
[=] { psLinuxUnderline(); },
QKeySequence::Underline);
psStrikeOut = edit->addAction(
tr::lng_menu_formatting_strike_out(tr::now),
this,
SLOT(psLinuxStrikeOut()),
[=] { psLinuxStrikeOut(); },
Ui::kStrikeOutSequence);
psMonospace = edit->addAction(
tr::lng_menu_formatting_monospace(tr::now),
this,
SLOT(psLinuxMonospace()),
[=] { psLinuxMonospace(); },
Ui::kMonospaceSequence);
psClearFormat = edit->addAction(
tr::lng_menu_formatting_clear(tr::now),
this,
SLOT(psLinuxClearFormat()),
[=] { psLinuxClearFormat(); },
Ui::kClearFormatSequence);
edit->addSeparator();
psSelectAll = edit->addAction(
tr::lng_mac_menu_select_all(tr::now),
this, SLOT(psLinuxSelectAll()),
this, [=] { psLinuxSelectAll(); },
QKeySequence::SelectAll);
edit->addSeparator();
@ -874,7 +884,7 @@ void MainWindow::createGlobalMenu() {
auto prefs = edit->addAction(
tr::lng_mac_menu_preferences(tr::now),
App::wnd(),
SLOT(showSettings()),
[=] { App::wnd()->showSettings(); },
QKeySequence(Qt::ControlModifier | Qt::Key_Comma));
prefs->setMenuRole(QAction::PreferencesRole);
@ -909,19 +919,19 @@ void MainWindow::createGlobalMenu() {
psAddContact = tools->addAction(
tr::lng_mac_menu_add_contact(tr::now),
App::wnd(),
SLOT(onShowAddContact()));
[=] { App::wnd()->onShowAddContact(); });
tools->addSeparator();
psNewGroup = tools->addAction(
tr::lng_mac_menu_new_group(tr::now),
App::wnd(),
SLOT(onShowNewGroup()));
[=] { App::wnd()->onShowNewGroup(); });
psNewChannel = tools->addAction(
tr::lng_mac_menu_new_channel(tr::now),
App::wnd(),
SLOT(onShowNewChannel()));
[=] { App::wnd()->onShowNewChannel(); });
auto help = psMainMenu->addMenu(tr::lng_linux_menu_help(tr::now));
@ -1066,7 +1076,7 @@ void MainWindow::updateGlobalMenuHook() {
ForceDisabled(psClearFormat, !markdownEnabled);
}
void MainWindow::onVisibleChanged(bool visible) {
void MainWindow::handleVisibleChanged(bool visible) {
if (AppMenuSupported && !_mainMenuPath.path().isEmpty()) {
if (visible) {
RegisterAppMenu(winId(), _mainMenuPath);

View File

@ -21,8 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Platform {
class MainWindow : public Window::MainWindow {
Q_OBJECT
public:
explicit MainWindow(not_null<Window::Controller*> controller);
@ -33,43 +31,12 @@ public:
style::color fg,
bool smallIcon) = 0;
void psShowTrayMenu();
static void LibsLoaded();
~MainWindow();
public slots:
void psShowTrayMenu();
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
void onSNIOwnerChanged(
const QString &service,
const QString &oldOwner,
const QString &newOwner);
void onAppMenuOwnerChanged(
const QString &service,
const QString &oldOwner,
const QString &newOwner);
void psLinuxUndo();
void psLinuxRedo();
void psLinuxCut();
void psLinuxCopy();
void psLinuxPaste();
void psLinuxDelete();
void psLinuxSelectAll();
void psLinuxBold();
void psLinuxItalic();
void psLinuxUnderline();
void psLinuxStrikeOut();
void psLinuxMonospace();
void psLinuxClearFormat();
void onVisibleChanged(bool visible);
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
protected:
void initHook() override;
void unreadCounterChangedHook() override;
@ -100,6 +67,7 @@ private:
void updateIconCounters();
void updateWaylandDecorationColors();
void handleVisibleChanged(bool visible);
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
StatusNotifierItem *_sniTrayIcon = nullptr;
@ -131,6 +99,31 @@ private:
void setSNITrayIcon(int counter, bool muted);
void attachToSNITrayIcon();
void handleSNIOwnerChanged(
const QString &service,
const QString &oldOwner,
const QString &newOwner);
void handleAppMenuOwnerChanged(
const QString &service,
const QString &oldOwner,
const QString &newOwner);
void psLinuxUndo();
void psLinuxRedo();
void psLinuxCut();
void psLinuxCopy();
void psLinuxPaste();
void psLinuxDelete();
void psLinuxSelectAll();
void psLinuxBold();
void psLinuxItalic();
void psLinuxUnderline();
void psLinuxStrikeOut();
void psLinuxMonospace();
void psLinuxClearFormat();
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
};

View File

@ -35,11 +35,11 @@ public:
void updateWindowIcon() override;
void psShowTrayMenu();
class Private;
public slots:
void psShowTrayMenu();
void psMacUndo();
void psMacRedo();
void psMacCut();

View File

@ -21,8 +21,6 @@ class PopupMenu;
namespace Platform {
class MainWindow : public Window::MainWindow {
Q_OBJECT
public:
explicit MainWindow(not_null<Window::Controller*> controller);
@ -58,11 +56,10 @@ public:
return _deltaTop;
}
~MainWindow();
public slots:
void psShowTrayMenu();
~MainWindow();
protected:
void initHook() override;
int32 screenNameChecksum(const QString &name) const override;