mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-24 00:03:13 +00:00
Custom title bar for macOS 10.10+ improved, colors in palette now.
This commit is contained in:
parent
494254496e
commit
8ff3779c9a
@ -49,7 +49,7 @@ lightButtonFgOver: lightButtonFg;
|
||||
menuIconFg: #a8a8a8;
|
||||
menuIconFgOver: #999999;
|
||||
|
||||
// custom title bar for Windows
|
||||
// custom title bar for Windows and macOS
|
||||
titleBg: windowOverBg;
|
||||
titleShadow: #00000003;
|
||||
titleButtonFg: #ababab;
|
||||
@ -57,6 +57,8 @@ titleButtonBgOver: #e5e5e5;
|
||||
titleButtonFgOver: #9a9a9a;
|
||||
titleButtonCloseBgOver: #e81123;
|
||||
titleButtonCloseFgOver: #ffffff;
|
||||
titleFgActive: #3e3c3e;
|
||||
titleFg: #acacac;
|
||||
|
||||
// tray icon
|
||||
trayCounterBg: #f23c34;
|
||||
|
@ -51,6 +51,8 @@ titleButtonBgOver: #e5e5e5;
|
||||
titleButtonFgOver: #9a9a9a;
|
||||
titleButtonCloseBgOver: #e81123;
|
||||
titleButtonCloseFgOver: #ffffff;
|
||||
titleFgActive: #3e3c3e;
|
||||
titleFg: #acacac;
|
||||
trayCounterBg: #f23c34;
|
||||
trayCounterBgMute: #888888;
|
||||
trayCounterFg: #ffffff;
|
||||
|
@ -103,7 +103,6 @@ MainWindow::MainWindow() {
|
||||
Notify::unreadCounterUpdated();
|
||||
}
|
||||
});
|
||||
subscribe(Global::RefUnreadCounterUpdate(), [this] { updateUnreadCounter(); });
|
||||
|
||||
resize(st::windowDefaultWidth, st::windowDefaultHeight);
|
||||
|
||||
@ -388,12 +387,6 @@ void MainWindow::setupMain(const MTPUser *self) {
|
||||
updateConnectingStatus();
|
||||
}
|
||||
|
||||
void MainWindow::updateUnreadCounter() {
|
||||
if (!Global::started() || App::quitting()) return;
|
||||
|
||||
psUpdateCounter();
|
||||
}
|
||||
|
||||
void MainWindow::showSettings() {
|
||||
if (_passcode) return;
|
||||
|
||||
|
@ -216,7 +216,6 @@ private slots:
|
||||
void onWindowActiveChanged();
|
||||
|
||||
private:
|
||||
void updateUnreadCounter();
|
||||
void showConnecting(const QString &text, const QString &reconnect = QString());
|
||||
void hideConnecting();
|
||||
|
||||
|
@ -43,8 +43,6 @@ public:
|
||||
void psRefreshTaskbarIcon() {
|
||||
}
|
||||
|
||||
void psUpdateCounter();
|
||||
|
||||
bool psHasNativeNotifications();
|
||||
|
||||
virtual QImage iconWithCounter(int size, int count, const style::color &bg, const style::color &fg, bool smallIcon) = 0;
|
||||
@ -61,6 +59,7 @@ public slots:
|
||||
|
||||
protected:
|
||||
void initHook() override;
|
||||
void unreadCounterChangedHook() override;
|
||||
|
||||
bool psHasTrayIcon() const;
|
||||
|
||||
|
@ -45,10 +45,6 @@ public:
|
||||
|
||||
bool psFilterNativeEvent(void *event);
|
||||
|
||||
bool eventFilter(QObject *obj, QEvent *evt) override;
|
||||
|
||||
void psUpdateCounter();
|
||||
|
||||
bool psHasNativeNotifications() {
|
||||
return !(QSysInfo::macVersion() < QSysInfo::MV_10_8);
|
||||
}
|
||||
@ -80,8 +76,12 @@ private slots:
|
||||
void onHideAfterFullScreen();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *evt) override;
|
||||
|
||||
void stateChangedHook(Qt::WindowState state) override;
|
||||
void initHook() override;
|
||||
void titleVisibilityChangedHook() override;
|
||||
void unreadCounterChangedHook() override;
|
||||
|
||||
QImage psTrayIcon(bool selected = false) const;
|
||||
bool psHasTrayIcon() const {
|
||||
@ -105,6 +105,8 @@ protected:
|
||||
|
||||
private:
|
||||
void createGlobalMenu();
|
||||
void updateTitleCounter();
|
||||
void updateIconCounters();
|
||||
|
||||
friend class Private;
|
||||
std_::unique_ptr<Private> _private;
|
||||
|
@ -169,11 +169,11 @@ void MainWindow::Private::initCustomTitle(NSWindow *window, NSView *view) {
|
||||
}
|
||||
|
||||
void MainWindow::Private::willEnterFullScreen() {
|
||||
_public->setTitleVisibility(false);
|
||||
_public->setTitleVisible(false);
|
||||
}
|
||||
|
||||
void MainWindow::Private::willExitFullScreen() {
|
||||
_public->setTitleVisibility(true);
|
||||
_public->setTitleVisible(true);
|
||||
}
|
||||
|
||||
void MainWindow::Private::enableShadow(WId winId) {
|
||||
@ -243,6 +243,10 @@ void MainWindow::initHook() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::titleVisibilityChangedHook() {
|
||||
updateTitleCounter();
|
||||
}
|
||||
|
||||
void MainWindow::onHideAfterFullScreen() {
|
||||
hide();
|
||||
}
|
||||
@ -269,7 +273,7 @@ void MainWindow::psSetupTrayIcon() {
|
||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection);
|
||||
App::wnd()->updateTrayMenu();
|
||||
}
|
||||
psUpdateCounter();
|
||||
updateIconCounters();
|
||||
|
||||
trayIcon->show();
|
||||
}
|
||||
@ -323,10 +327,17 @@ void _placeCounter(QImage &img, int size, int count, const style::color &bg, con
|
||||
p.drawText(size - w - d - skip, size - f->height + f->ascent - skip, cnt);
|
||||
}
|
||||
|
||||
void MainWindow::psUpdateCounter() {
|
||||
int32 counter = App::histories().unreadBadge();
|
||||
void MainWindow::updateTitleCounter() {
|
||||
setWindowTitle(titleVisible() ? QString() : titleText());
|
||||
}
|
||||
|
||||
setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
|
||||
void MainWindow::unreadCounterChangedHook() {
|
||||
updateTitleCounter();
|
||||
updateIconCounters();
|
||||
}
|
||||
|
||||
void MainWindow::updateIconCounters() {
|
||||
auto counter = App::histories().unreadBadge();
|
||||
|
||||
QString cnt = (counter < 1000) ? QString("%1").arg(counter) : QString("..%1").arg(counter % 100, 2, 10, QChar('0'));
|
||||
_private->setWindowBadge(counter ? cnt : QString());
|
||||
|
@ -28,16 +28,20 @@ class PlainShadow;
|
||||
|
||||
namespace Platform {
|
||||
|
||||
class TitleWidget : public Window::TitleWidget {
|
||||
class MainWindow;
|
||||
|
||||
class TitleWidget : public Window::TitleWidget, private base::Subscriber {
|
||||
public:
|
||||
TitleWidget(QWidget *parent, int height);
|
||||
TitleWidget(MainWindow *parent, int height);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
||||
|
||||
private:
|
||||
ChildWidget<Ui::PlainShadow> _shadow;
|
||||
QFont _font;
|
||||
|
||||
};
|
||||
|
||||
|
@ -27,26 +27,62 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
|
||||
namespace Platform {
|
||||
|
||||
TitleWidget::TitleWidget(QWidget *parent, int height) : Window::TitleWidget(parent)
|
||||
TitleWidget::TitleWidget(MainWindow *parent, int height) : Window::TitleWidget(parent)
|
||||
, _shadow(this, st::titleShadow) {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
resize(width(), height);
|
||||
|
||||
#ifndef OS_MAC_OLD
|
||||
QStringList families = { qsl(".SF NS Text"), qsl("Helvetica Neue") };
|
||||
for (auto family : families) {
|
||||
_font.setFamily(family);
|
||||
if (QFontInfo(_font).family() == _font.family()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif // OS_MAC_OLD
|
||||
|
||||
if (QFontInfo(_font).family() == _font.family()) {
|
||||
_font.setPixelSize((height * 15) / 24);
|
||||
} else {
|
||||
_font = st::normalFont;
|
||||
}
|
||||
|
||||
subscribe(Global::RefUnreadCounterUpdate(), [this] { update(); });
|
||||
}
|
||||
|
||||
void TitleWidget::paintEvent(QPaintEvent *e) {
|
||||
Painter(this).fillRect(rect(), st::titleBg);
|
||||
Painter p(this);
|
||||
|
||||
p.fillRect(rect(), st::titleBg);
|
||||
|
||||
p.setPen(isActiveWindow() ? st::titleFgActive : st::titleFg);
|
||||
p.setFont(_font);
|
||||
|
||||
p.drawText(rect(), static_cast<MainWindow*>(parentWidget())->titleText(), style::al_center);
|
||||
}
|
||||
|
||||
void TitleWidget::resizeEvent(QResizeEvent *e) {
|
||||
_shadow->setGeometry(0, height() - st::lineWidth, width(), st::lineWidth);
|
||||
}
|
||||
|
||||
void TitleWidget::mouseDoubleClickEvent(QMouseEvent *e) {
|
||||
auto window = parentWidget();
|
||||
if (window->windowState() == Qt::WindowMaximized) {
|
||||
window->setWindowState(Qt::WindowNoState);
|
||||
} else {
|
||||
window->setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
}
|
||||
|
||||
Window::TitleWidget *CreateTitleWidget(QWidget *parent) {
|
||||
#ifndef OS_MAC_OLD
|
||||
if (auto window = qobject_cast<Platform::MainWindow*>(parent)) {
|
||||
if (auto height = window->getCustomTitleHeight()) {
|
||||
return new TitleWidget(parent, height);
|
||||
return new TitleWidget(window, height);
|
||||
}
|
||||
}
|
||||
#endif // !OS_MAC_OLD
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -683,7 +683,7 @@ void MainWindow::psSetupTrayIcon() {
|
||||
connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray()));
|
||||
App::wnd()->updateTrayMenu();
|
||||
}
|
||||
psUpdateCounter();
|
||||
updateIconCounters();
|
||||
|
||||
trayIcon->show();
|
||||
}
|
||||
@ -723,7 +723,12 @@ void MainWindow::psUpdateWorkmode() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::psUpdateCounter() {
|
||||
void MainWindow::unreadCounterChangedHook() {
|
||||
setWindowTitle(titleText());
|
||||
updateIconCounters();
|
||||
}
|
||||
|
||||
void MainWindow::updateIconCounters() {
|
||||
auto counter = App::histories().unreadBadge();
|
||||
auto muted = App::histories().unreadOnlyMuted();
|
||||
|
||||
@ -746,7 +751,6 @@ void MainWindow::psUpdateCounter() {
|
||||
trayIcon->setIcon(forTrayIcon);
|
||||
}
|
||||
|
||||
setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
|
||||
psDestroyIcons();
|
||||
ps_iconSmall = createHIconFromQIcon(iconSmall, iconSizeSmall.width(), iconSizeSmall.height());
|
||||
ps_iconBig = createHIconFromQIcon(iconBig, iconSizeBig.width(), iconSizeBig.height());
|
||||
|
@ -50,8 +50,6 @@ public:
|
||||
|
||||
void psRefreshTaskbarIcon();
|
||||
|
||||
void psUpdateCounter();
|
||||
|
||||
bool psHasNativeNotifications();
|
||||
|
||||
virtual QImage iconWithCounter(int size, int count, const style::color &bg, const style::color &fg, bool smallIcon) = 0;
|
||||
@ -93,6 +91,7 @@ public slots:
|
||||
protected:
|
||||
void initHook() override;
|
||||
int32 screenNameChecksum(const QString &name) const override;
|
||||
void unreadCounterChangedHook() override;
|
||||
|
||||
bool psHasTrayIcon() const {
|
||||
return trayIcon;
|
||||
@ -110,6 +109,8 @@ protected:
|
||||
QTimer psUpdatedPositionTimer;
|
||||
|
||||
private:
|
||||
void updateIconCounters();
|
||||
|
||||
void psDestroyIcons();
|
||||
|
||||
static UINT _taskbarCreatedMsgId;
|
||||
|
@ -30,7 +30,8 @@ namespace Window {
|
||||
|
||||
MainWindow::MainWindow() : QWidget()
|
||||
, _positionUpdatedTimer(this)
|
||||
, _body(this) {
|
||||
, _body(this)
|
||||
, _titleText(qsl("Telegram")) {
|
||||
subscribe(Theme::Background(), [this](const Theme::BackgroundUpdate &data) {
|
||||
using Type = Theme::BackgroundUpdate::Type;
|
||||
if (data.type == Type::TestingTheme || data.type == Type::RevertingTheme || data.type == Type::ApplyingTheme) {
|
||||
@ -39,6 +40,7 @@ MainWindow::MainWindow() : QWidget()
|
||||
}
|
||||
}
|
||||
});
|
||||
subscribe(Global::RefUnreadCounterUpdate(), [this] { updateUnreadCounter(); });
|
||||
}
|
||||
|
||||
void MainWindow::init() {
|
||||
@ -105,11 +107,16 @@ void MainWindow::positionUpdated() {
|
||||
_positionUpdatedTimer->start(SaveWindowPositionTimeout);
|
||||
}
|
||||
|
||||
void MainWindow::setTitleVisibility(bool visible) {
|
||||
bool MainWindow::titleVisible() const {
|
||||
return _title && !_title->isHidden();
|
||||
}
|
||||
|
||||
void MainWindow::setTitleVisible(bool visible) {
|
||||
if (_title && (_title->isHidden() == visible)) {
|
||||
_title->setVisible(visible);
|
||||
updateControlsGeometry();
|
||||
}
|
||||
titleVisibilityChangedHook();
|
||||
}
|
||||
|
||||
int32 MainWindow::screenNameChecksum(const QString &name) const {
|
||||
@ -134,6 +141,15 @@ void MainWindow::updateControlsGeometry() {
|
||||
_body->setGeometry(0, bodyTop, width(), height() - bodyTop);
|
||||
}
|
||||
|
||||
void MainWindow::updateUnreadCounter() {
|
||||
if (!Global::started() || App::quitting()) return;
|
||||
|
||||
auto counter = App::histories().unreadBadge();
|
||||
_titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram");
|
||||
|
||||
unreadCounterChangedHook();
|
||||
}
|
||||
|
||||
void MainWindow::savePosition(Qt::WindowState state) {
|
||||
if (state == Qt::WindowActive) state = windowHandle()->windowState();
|
||||
if (state == Qt::WindowMinimized || !positionInited()) return;
|
||||
|
@ -40,7 +40,11 @@ public:
|
||||
}
|
||||
void positionUpdated();
|
||||
|
||||
void setTitleVisibility(bool visible);
|
||||
bool titleVisible() const;
|
||||
void setTitleVisible(bool visible);
|
||||
QString titleText() const {
|
||||
return _titleText;
|
||||
}
|
||||
|
||||
virtual void closeWithoutDestroy();
|
||||
|
||||
@ -61,6 +65,12 @@ protected:
|
||||
virtual void stateChangedHook(Qt::WindowState state) {
|
||||
}
|
||||
|
||||
virtual void titleVisibilityChangedHook() {
|
||||
}
|
||||
|
||||
virtual void unreadCounterChangedHook() {
|
||||
}
|
||||
|
||||
// This one is overriden in Windows for historical reasons.
|
||||
virtual int32 screenNameChecksum(const QString &name) const;
|
||||
|
||||
@ -73,6 +83,7 @@ private slots:
|
||||
|
||||
private:
|
||||
void updateControlsGeometry();
|
||||
void updateUnreadCounter();
|
||||
void initSize();
|
||||
|
||||
ChildObject<QTimer> _positionUpdatedTimer;
|
||||
@ -81,6 +92,8 @@ private:
|
||||
ChildWidget<TitleWidget> _title = { nullptr };
|
||||
ChildWidget<QWidget> _body;
|
||||
|
||||
QString _titleText;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Window
|
||||
|
Loading…
Reference in New Issue
Block a user