Skip to content

Commit c0b7efc

Browse files
committed
Added context menu to EventNotifier widget.
Added possibility to clear all events using EventNotifier context menu. Dark New Classic theme renamed to Stylized Classic. Stylized Classic theme optimizations related to CSS.
1 parent 993dabf commit c0b7efc

File tree

9 files changed

+105
-57
lines changed

9 files changed

+105
-57
lines changed

src/mainwin.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,17 @@ MainWin::MainWin(bool _onTop, bool _asTool, PsiCon *psi) :
519519
d->eventNotifier->setText("");
520520
d->vb_roster->addWidget(d->eventNotifier);
521521
connect(d->eventNotifier, &EventNotifier::clicked, this, [this](int btn) {
522-
if (btn == Qt::MiddleButton)
522+
if (btn == Qt::MiddleButton || btn == Qt::LeftButton)
523523
emit recvNextEvent();
524-
if (btn == Qt::LeftButton)
525-
doRecvNextEvent();
524+
});
525+
connect(d->eventNotifier, &EventNotifier::clearEventQueue, this, [this]() {
526+
if (QMessageBox::question(this, tr("Question"), tr("Are you sure you want to clear all events?"))
527+
== QMessageBox::Yes) {
528+
auto accounts = d->psi->contactList()->accounts();
529+
for (const auto &account : accounts) {
530+
account->eventQueue()->clear();
531+
}
532+
}
526533
});
527534

528535
#ifdef Q_OS_WIN

src/widgets/eventnotifier.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
*/
1919

2020
#include "eventnotifier.h"
21+
#include <QAction>
2122
#include <QHBoxLayout>
23+
#include <QLabel>
24+
#include <QMenu>
25+
#include <QMouseEvent>
2226

27+
/**
28+
* \class ClickableLabel
29+
* \brief QLabel that reacts on mouse click events.
30+
*/
2331
ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent)
2432
{
2533
setMinimumWidth(48);
@@ -32,6 +40,10 @@ void ClickableLabel::mouseReleaseEvent(QMouseEvent *e)
3240
e->ignore();
3341
}
3442

43+
/**
44+
* \class EventNotifier
45+
* \brief A widget that appears at the bottom of roster to control incoming events.
46+
*/
3547
EventNotifier::EventNotifier(QWidget *parent, const char *name) :
3648
QFrame { parent }, eventIcon(new IconLabel(this)), eventLabel(new ClickableLabel(this))
3749
{
@@ -51,6 +63,19 @@ void EventNotifier::mouseReleaseEvent(QMouseEvent *e)
5163
e->ignore();
5264
}
5365

66+
void EventNotifier::contextMenuEvent(QContextMenuEvent *e)
67+
{
68+
// create popup menu
69+
QMenu popupMenu;
70+
QAction *clearEventsAct = new QAction(tr("Clear all events"), &popupMenu);
71+
QAction *readNextEventAct = new QAction(tr("Read next event"), &popupMenu);
72+
connect(clearEventsAct, &QAction::triggered, this, [this]() { emit clearEventQueue(); });
73+
connect(readNextEventAct, &QAction::triggered, this, [this]() { emit clicked(Qt::LeftButton); });
74+
popupMenu.addActions({ readNextEventAct, clearEventsAct });
75+
popupMenu.exec(e->globalPos());
76+
e->accept();
77+
}
78+
5479
void EventNotifier::setPsiIcon(PsiIcon *icon) { eventIcon->setPsiIcon(icon); }
5580

5681
void EventNotifier::setPsiIcon(const QString &name) { eventIcon->setPsiIcon(name); }

src/widgets/eventnotifier.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
#include "iconlabel.h"
2424
#include "iconset.h"
25-
#include <QLabel>
26-
#include <QMouseEvent>
2725
#include <QWidget>
2826

27+
class QLabel;
28+
class QMouseEvent;
29+
2930
class ClickableLabel : public QLabel {
3031
Q_OBJECT
3132
public:
@@ -49,9 +50,11 @@ class EventNotifier : public QFrame {
4950

5051
signals:
5152
void clicked(int);
53+
void clearEventQueue();
5254

5355
protected:
5456
void mouseReleaseEvent(QMouseEvent *);
57+
void contextMenuEvent(QContextMenuEvent *e);
5558

5659
private:
5760
IconLabel *eventIcon;

themes/chatview.qrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<file>chatview/psi/LunnaCat_Classic/images/ScrollBarArrowDown.png</file>
1111
<file>chatview/psi/LunnaCat_Classic/screenshot.png</file>
1212
<file>chatview/psi/LunnaCat_Classic/load.js</file>
13-
<file>chatview/psi/dark_new_classic/index.html</file>
14-
<file>chatview/psi/dark_new_classic/screenshot.png</file>
15-
<file>chatview/psi/dark_new_classic/load.js</file>
13+
<file>chatview/psi/stylized_classic/index.html</file>
14+
<file>chatview/psi/stylized_classic/screenshot.png</file>
15+
<file>chatview/psi/stylized_classic/load.js</file>
1616
<file>chatview/psi/classic/index.html</file>
1717
<file>chatview/psi/classic/load.js</file>
1818
<file>chatview/psi/new_classic/index.html</file>

themes/chatview/psi/dark_new_classic/load.js

-1
This file was deleted.

themes/chatview/psi/dark_new_classic/index.html themes/chatview/psi/stylized_classic/index.html

+52-48
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@
112112
"options.ui.look.colors.messages.link-visited" : cssLinkVisited
113113
}
114114

115+
var sstyle = document.getElementById('scrollStyle');
116+
if (sstyle && document.body.contains(sstyle)) {
117+
document.body.removeChild(sstyle);
118+
}
119+
var scrollStyle = document.createElement('style');
120+
scrollStyle.type = 'text/css';
121+
scrollStyle.id = 'scrollStyle';
122+
123+
function setScrollBarElemStyle(element, style) {
124+
return element + " { background-color: " + style.backgroundColor +"; border: " + style.border + "; border-radius: " + style.borderRadius + "; } ";
125+
}
126+
115127
var applyPsiSettings = function() {
116128
util.getFont(function(cssFont){util.updateObject(cssBody, cssFont)});
117129
util.getPaletteColor("Base", function(color){cssBody.backgroundColor = color});
@@ -136,56 +148,47 @@
136148
shared.chatElement.removeChild(d);
137149
}
138150
});
139-
}
140-
141-
// This function converts string to CSSStyleSheet
142-
function CSSString2CSSStyleSheet ( css ) {
143-
const style = document.createElement ( 'style' );
144-
style.innerText = css;
145-
document.head.appendChild ( style );
146-
const {sheet} = style;
147-
document.head.removeChild ( style );
148-
return sheet;
149-
}
150151

151-
function setScrollBarElemStyle(element, style) {
152-
return element + " { background-color: " + style.backgroundColor +"; border: " + style.border + "; border-radius: " + style.borderRadius + "; }";
153-
}
154-
155-
//set chat scrollbar style from qstylesheet
156-
util.psiOption("options.ui.chat.css", function(val) {
157-
if (!val) { return; }
158-
//replace :: symbols by _ to parse qss
159-
var fixedText = val.replace(/::/g, "_");
160-
const opCSSRules = CSSString2CSSStyleSheet(fixedText.toLowerCase());
161-
for (let i=0; i < opCSSRules.cssRules.length; i++) {
162-
const rule = opCSSRules.cssRules[i];
163-
const ruleText = rule.cssText;
164-
const ruleStyle = rule.style;
165-
if (ruleText.startsWith("qscrollbar_handle:hover")) {
166-
var newRule = setScrollBarElemStyle("body::-webkit-scrollbar-thumb:hover", ruleStyle);
167-
themeStyle.insertRule(newRule, themeStyle.cssRules.length);
168-
} else
169-
if (ruleText.startsWith("qscrollbar_handle") && !ruleText.includes("hover")) {
170-
var newRule = setScrollBarElemStyle("body::-webkit-scrollbar-thumb", ruleStyle);
171-
themeStyle.insertRule(newRule, themeStyle.cssRules.length);
172-
} else
173-
if (ruleText.startsWith("qscrollbar:vertical") && !ruleText.includes("hover")) {
174-
//count scrollbar width in pexels: width - left margin - right margin
175-
var cssWidth = parseInt(ruleStyle.width) - (parseInt(ruleStyle.marginLeft) + parseInt(ruleStyle.marginRight));
176-
var newRule = "body::-webkit-scrollbar { width: " + cssWidth + "px; }";
177-
themeStyle.insertRule(newRule, themeStyle.cssRules.length);
178-
} else
179-
if (ruleText.startsWith("qscrollbar:vertical:hover")) {
180-
var newRule = setScrollBarElemStyle("body::-webkit-scrollbar-track:hover", ruleStyle);
181-
themeStyle.insertRule(newRule, themeStyle.cssRules.length);
182-
} else
183-
if (ruleText.startsWith("qscrollbar") && !ruleText.includes("horizontal") && !ruleText.includes("_")) {
184-
var newRule = setScrollBarElemStyle("body::-webkit-scrollbar-track, body::-webkit-scrollbar", ruleStyle);
185-
themeStyle.insertRule(newRule, themeStyle.cssRules.length);
152+
//set chat scrollbar style from qstylesheet
153+
util.psiOption("options.ui.chat.css", function(val) {
154+
scrollStyle.innerText = "";
155+
if (!val) { return; }
156+
//replace :: symbols by _ to parse qss
157+
var tmpText = val.replace(/::/g, "_");
158+
var fixedText = tmpText.replace(/qframe#log/gi, "qframe_log");
159+
const opCSSRules = util.CSSString2CSSStyleSheet(fixedText.toLowerCase());
160+
var scrollCSS = "";
161+
for (let i=0; i < opCSSRules.cssRules.length; i++) {
162+
const rule = opCSSRules.cssRules[i];
163+
const ruleText = rule.cssText;
164+
const ruleStyle = rule.style;
165+
if (ruleText.startsWith("qscrollbar_handle:hover")) {
166+
scrollCSS += setScrollBarElemStyle("body::-webkit-scrollbar-thumb:hover", ruleStyle);
167+
} else
168+
if (ruleText.startsWith("qscrollbar_handle") && !ruleText.includes("hover")) {
169+
scrollCSS += setScrollBarElemStyle("body::-webkit-scrollbar-thumb", ruleStyle);
170+
} else
171+
if (ruleText.startsWith("qscrollbar:vertical") && !ruleText.includes("hover")) {
172+
//count scrollbar width in pexels: width - left margin - right margin
173+
var cssWidth = parseInt(ruleStyle.width) - (parseInt(ruleStyle.marginLeft) + parseInt(ruleStyle.marginRight));
174+
scrollCSS += "body::-webkit-scrollbar { width: " + cssWidth + "px; } ";
175+
} else
176+
if (ruleText.startsWith("qscrollbar:vertical:hover")) {
177+
scrollCSS += setScrollBarElemStyle("body::-webkit-scrollbar-track:hover", ruleStyle);
178+
} else
179+
if (ruleText.startsWith("qscrollbar") && !ruleText.includes("horizontal") && !ruleText.includes("_")) {
180+
scrollCSS += setScrollBarElemStyle("body::-webkit-scrollbar-track, body::-webkit-scrollbar", ruleStyle);
181+
}
182+
if (ruleText.startsWith("qframe_log")) {
183+
var chatBgColor = ruleStyle.backgroundColor;
184+
var chatBrdColor = ruleStyle.borderColor;
185+
var trackbarTmp = "hr { height:1px; border:1px solid black; border-color:" + chatBgColor + " " + chatBrdColor + " " + chatBrdColor + " " + chatBgColor + ";} ";
186+
scrollCSS += trackbarTmp;
187+
}
186188
}
187-
}
188-
});
189+
scrollStyle.innerText = scrollCSS;
190+
});
191+
}
189192

190193
shared.initTheme({
191194
chatElement : document.body,
@@ -275,6 +278,7 @@
275278
});
276279

277280
applyPsiSettings();
281+
document.body.appendChild(scrollStyle);
278282

279283
shared.session.signalInited();
280284

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
srvLoader.setMetaData({name: "Stylized Classic"});

themes/chatview/util.js

+9
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,15 @@ function initPsiTheme() {
521521
return true;
522522
}
523523
return false;
524+
},
525+
526+
CSSString2CSSStyleSheet : function(css) {
527+
const style = document.createElement ( 'style' );
528+
style.innerText = css;
529+
document.head.appendChild ( style );
530+
const {sheet} = style;
531+
document.head.removeChild ( style );
532+
return sheet;
524533
}
525534
},
526535

0 commit comments

Comments
 (0)