Skip to content

Commit 2a4adde

Browse files
committed
Use EventNotifier widget instead of EventNotifierAction on Toolbar.
Added hack to detect Windows 11. Some code modernize
1 parent a07d702 commit 2a4adde

12 files changed

+165
-254
lines changed

options/default.xml

-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ QLineEdit#le_status_text {
549549
<button_options type="QKeySequence" comment="Options"></button_options>
550550
<button_status type="QKeySequence" comment="Status"></button_status>
551551
<enable_groups type="QKeySequence" comment="Enable Groups"></enable_groups>
552-
<event_notifier type="QKeySequence" comment="Event Notifier"></event_notifier>
553552
<view_groups type="QKeySequence" comment="View Groups"></view_groups>
554553
<show_offline type="QKeySequence" comment="Show Offline Contacts"></show_offline>
555554
<show_away type="QKeySequence" comment="Show Away Contacts"></show_away>

src/mainwin.cpp

+33-31
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "avcall/avcall.h"
2929
#include "common.h"
3030
#include "desktoputil.h"
31+
#include "eventnotifier.h"
3132
#include "geolocationdlg.h"
3233
#include "globalstatusmenu.h"
3334
#include "mainwin_p.h"
@@ -104,7 +105,7 @@ class MainWin::Private {
104105
~Private();
105106

106107
bool onTop, asTool;
107-
QMenu * mainMenu, *optionsMenu, *toolsMenu;
108+
QMenu *mainMenu, *optionsMenu, *toolsMenu;
108109
GlobalStatusMenu *statusMenu;
109110
#ifdef Q_OS_LINUX
110111
// Status menu for MenuBar.
@@ -114,31 +115,31 @@ class MainWin::Private {
114115
int sbState;
115116
QString nickname;
116117
PsiTrayIcon *tray;
117-
QMenu * trayMenu;
118+
QMenu *trayMenu;
118119
#ifdef Q_OS_MAC
119120
QMenu *dockMenu;
120121
#endif
121122
QVBoxLayout *vb_roster;
122-
QSplitter * splitter;
123-
TabDlg * mainTabs;
123+
QSplitter *splitter;
124+
TabDlg *mainTabs;
124125
QString statusTip;
125-
PsiToolBar * viewToolBar;
126+
PsiToolBar *viewToolBar;
126127
int tabsSize;
127128
int rosterSize;
128129
bool isLeftRoster;
129130

130-
PopupAction * optionsButton, *statusButton;
131-
IconActionGroup * statusGroup, *viewGroups;
132-
IconAction * statusSmallerAlt;
133-
EventNotifierAction *eventNotifier;
134-
PsiCon * psi;
135-
MainWin * mainWin;
136-
RosterAvatarFrame * rosterAvatar;
131+
PopupAction *optionsButton, *statusButton;
132+
IconActionGroup *statusGroup, *viewGroups;
133+
IconAction *statusSmallerAlt;
134+
EventNotifier *eventNotifier;
135+
PsiCon *psi;
136+
MainWin *mainWin;
137+
RosterAvatarFrame *rosterAvatar;
137138
QPointer<PsiAccount> defaultAccount;
138139

139-
QLineEdit * searchText;
140+
QLineEdit *searchText;
140141
QToolButton *searchPb;
141-
QWidget * searchWidget;
142+
QWidget *searchWidget;
142143

143144
QTimer *hideTimer;
144145

@@ -182,7 +183,7 @@ MainWin::Private::Private(PsiCon *_psi, MainWin *_mainWin) :
182183

183184
statusGroup = static_cast<IconActionGroup *>(getAction("status_group"));
184185
viewGroups = static_cast<IconActionGroup *>(getAction("view_groups"));
185-
eventNotifier = static_cast<EventNotifierAction *>(getAction("event_notifier"));
186+
eventNotifier = nullptr;
186187

187188
optionsButton = static_cast<PopupAction *>(getAction("button_options"));
188189
statusButton = static_cast<PopupAction *>(getAction("button_status"));
@@ -514,6 +515,16 @@ MainWin::MainWin(bool _onTop, bool _asTool, PsiCon *psi) :
514515
buildToolbars();
515516
// setUnifiedTitleAndToolBarOnMac(true);
516517

518+
d->eventNotifier = new EventNotifier(this, "EventNotifier");
519+
d->eventNotifier->setText("");
520+
d->vb_roster->addWidget(d->eventNotifier);
521+
connect(d->eventNotifier, &EventNotifier::clicked, this, [this](int btn) {
522+
if (btn == Qt::MiddleButton)
523+
emit recvNextEvent();
524+
if (btn == Qt::LeftButton)
525+
doRecvNextEvent();
526+
});
527+
517528
#ifdef Q_OS_WIN
518529
updateWinTaskbar(_asTool);
519530
#endif
@@ -578,7 +589,7 @@ void MainWin::registerAction(IconAction *action)
578589
struct MenuAction {
579590
const char *name;
580591
const char *signal;
581-
QObject * receiver;
592+
QObject *receiver;
582593
const char *slot;
583594
};
584595
std::vector<MenuAction> actionlist = {
@@ -617,9 +628,6 @@ void MainWin::registerAction(IconAction *action)
617628
{ "set_geoloc", activated, this, SLOT(actSetGeolocActivated()) },
618629
#endif
619630

620-
{ "event_notifier", SIGNAL(clicked(int)), this, SLOT(statusClicked(int)) },
621-
{ "event_notifier", activated, this, SLOT(doRecvNextEvent()) },
622-
623631
{ "help_readme", activated, this, SLOT(actReadmeActivated()) },
624632
{ "help_online_wiki", activated, this, SLOT(actOnlineWikiActivated()) },
625633
{ "help_online_home", activated, this, SLOT(actOnlineHomeActivated()) },
@@ -663,7 +671,7 @@ void MainWin::registerAction(IconAction *action)
663671

664672
struct {
665673
const char *name;
666-
QObject * sender;
674+
QObject *sender;
667675
const char *signal;
668676
const char *slot;
669677
bool checked;
@@ -873,7 +881,6 @@ void MainWin::buildToolbars()
873881
tb->updateVisibility();
874882
}
875883

876-
// d->eventNotifier->updateVisibility();
877884
setUpdatesEnabled(true);
878885

879886
// in case we have floating toolbars, they have inherited the 'no updates enabled'
@@ -1057,7 +1064,7 @@ void MainWin::actDiagQCAKeyStoreActivated()
10571064

10581065
void MainWin::actChooseStatusActivated()
10591066
{
1060-
PsiOptions * o = PsiOptions::instance();
1067+
PsiOptions *o = PsiOptions::instance();
10611068
XMPP::Status::Type lastStatus
10621069
= XMPP::Status::txt2type(PsiOptions::instance()->getOption("options.status.last-status").toString());
10631070
StatusSetDlg *w = new StatusSetDlg(d->psi, makeLastStatus(lastStatus), lastPriorityNotEmpty());
@@ -1649,9 +1656,11 @@ void MainWin::updateReadNext(PsiIcon *anim, int amount)
16491656

16501657
if (d->nextAmount <= 0) {
16511658
d->eventNotifier->hide();
1652-
d->eventNotifier->setMessage("");
1659+
d->eventNotifier->setText("");
1660+
d->eventNotifier->setPsiIcon("");
16531661
} else {
1654-
d->eventNotifier->setMessage(QString("<b>") + numEventsString(d->nextAmount) + "</b>");
1662+
d->eventNotifier->setPsiIcon(anim);
1663+
d->eventNotifier->setText(QString("<b>") + numEventsString(d->nextAmount) + "</b>");
16551664
d->eventNotifier->show();
16561665
// make sure it shows
16571666
// qApp->processEvents();
@@ -1704,13 +1713,6 @@ void MainWin::updateTray()
17041713

17051714
void MainWin::doRecvNextEvent() { emit recvNextEvent(); }
17061715

1707-
void MainWin::statusClicked(int x)
1708-
{
1709-
if (x == Qt::MiddleButton) {
1710-
emit recvNextEvent();
1711-
}
1712-
}
1713-
17141716
PsiTrayIcon *MainWin::psiTrayIcon() { return d->tray; }
17151717

17161718
void MainWin::numAccountsChanged()

src/mainwin.h

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ private slots:
112112
void trayHideShow();
113113

114114
void doRecvNextEvent();
115-
void statusClicked(int);
116115
void try2tryCloseProgram();
117116
void tryCloseProgram();
118117

src/mainwin_p.cpp

+1-158
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class PopupAction::Private : public QObject {
233233
public:
234234
QSizePolicy size;
235235
QList<PopupActionButton *> buttons;
236-
PsiIcon * icon;
236+
PsiIcon *icon;
237237
bool showText;
238238

239239
Private(QObject *parent) : QObject(parent)
@@ -352,32 +352,6 @@ PopupAction &PopupAction::operator=(const PopupAction &from)
352352
return *this;
353353
}
354354

355-
//----------------------------------------------------------------------------
356-
// MLabel -- a clickable label
357-
//----------------------------------------------------------------------------
358-
359-
MLabel::MLabel(QWidget *parent, const char *name) : QLabel(parent)
360-
{
361-
setObjectName(name);
362-
setMinimumWidth(48);
363-
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
364-
setFrameStyle(QFrame::Panel | QFrame::Sunken);
365-
}
366-
367-
void MLabel::mouseReleaseEvent(QMouseEvent *e)
368-
{
369-
emit clicked(int(e->button()));
370-
e->ignore();
371-
}
372-
373-
void MLabel::mouseDoubleClickEvent(QMouseEvent *e)
374-
{
375-
if (e->button() == Qt::LeftButton)
376-
emit doubleClicked();
377-
378-
e->ignore();
379-
}
380-
381355
//----------------------------------------------------------------------------
382356
// MAction
383357
//----------------------------------------------------------------------------
@@ -515,135 +489,4 @@ bool SeparatorAction::addTo(QWidget *w)
515489

516490
IconAction *SeparatorAction::copy() const { return new SeparatorAction(nullptr); }
517491

518-
//----------------------------------------------------------------------------
519-
// EventNotifierAction
520-
//----------------------------------------------------------------------------
521-
522-
class EventNotifierAction::Private {
523-
public:
524-
Private() = default;
525-
526-
QList<MLabel *> labels;
527-
bool hide = false;
528-
QString message;
529-
};
530-
531-
EventNotifierAction::EventNotifierAction(QObject *parent, const char *name) : IconAction(parent, name)
532-
{
533-
d = new Private;
534-
setText(tr("<Event notifier>"));
535-
d->hide = true;
536-
}
537-
538-
EventNotifierAction::~EventNotifierAction() { delete d; }
539-
540-
bool EventNotifierAction::addTo(QWidget *w)
541-
{
542-
if (w) {
543-
MLabel *label = new MLabel(w, "EventNotifierAction::MLabel");
544-
label->setText(d->message);
545-
d->labels.append(label);
546-
connect(label, SIGNAL(destroyed()), SLOT(objectDestroyed()));
547-
connect(label, SIGNAL(doubleClicked()), SIGNAL(triggered()));
548-
connect(label, SIGNAL(clicked(int)), SIGNAL(clicked(int)));
549-
550-
QToolBar *toolbar = dynamic_cast<QToolBar *>(w);
551-
if (!toolbar) {
552-
QLayout *layout = w->layout();
553-
if (layout)
554-
layout->addWidget(label);
555-
} else {
556-
toolbar->addWidget(label);
557-
}
558-
559-
if (d->hide)
560-
hide();
561-
562-
return true;
563-
}
564-
565-
return false;
566-
}
567-
568-
void EventNotifierAction::setMessage(const QString &m)
569-
{
570-
d->message = m;
571-
572-
for (MLabel *label : qAsConst(d->labels)) {
573-
label->setText(d->message);
574-
}
575-
}
576-
577-
void EventNotifierAction::objectDestroyed()
578-
{
579-
MLabel *label = static_cast<MLabel *>(sender());
580-
d->labels.removeAll(label);
581-
}
582-
583-
void EventNotifierAction::hide()
584-
{
585-
d->hide = true;
586-
587-
for (MLabel *label : qAsConst(d->labels)) {
588-
label->hide();
589-
PsiToolBar *toolBar = dynamic_cast<PsiToolBar *>(label->parent());
590-
if (toolBar) {
591-
int found = 0;
592-
const auto &widgets = toolBar->findChildren<QWidget *>();
593-
for (QWidget *widget : widgets) {
594-
if (!widget->objectName().startsWith("qt_")
595-
&& !QString(widget->metaObject()->className()).startsWith("QToolBar")
596-
&& !QString(widget->metaObject()->className()).startsWith("QMenu")
597-
&& QString(widget->metaObject()->className()) != "Oxygen::TransitionWidget") // dirty hack
598-
{
599-
found++;
600-
}
601-
}
602-
603-
if (found == 1) // only MLabel is on ToolBar
604-
// We should not hide toolbar, if it should be visible (user set `enabled` in options)
605-
// toolBar->hide();
606-
toolBar->updateVisibility();
607-
}
608-
}
609-
}
610-
611-
void EventNotifierAction::show()
612-
{
613-
d->hide = false;
614-
615-
for (MLabel *label : qAsConst(d->labels)) {
616-
label->show();
617-
QToolBar *toolBar = dynamic_cast<QToolBar *>(label->parent());
618-
if (toolBar)
619-
toolBar->show();
620-
}
621-
}
622-
623-
void EventNotifierAction::updateVisibility()
624-
{
625-
if (d->hide)
626-
hide();
627-
else
628-
show();
629-
}
630-
631-
IconAction *EventNotifierAction::copy() const
632-
{
633-
EventNotifierAction *act = new EventNotifierAction(nullptr);
634-
635-
*act = *this;
636-
637-
return act;
638-
}
639-
640-
EventNotifierAction &EventNotifierAction::operator=(const EventNotifierAction &from)
641-
{
642-
*(static_cast<IconAction *>(this)) = from;
643-
644-
d->hide = from.d->hide;
645-
646-
return *this;
647-
}
648-
649492
#include "mainwin_p.moc"

0 commit comments

Comments
 (0)