This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstickywidget.cpp
111 lines (100 loc) · 4.3 KB
/
stickywidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "stickywidget.h"
#include "daemon.h"
StickyWidget::StickyWidget(QWidget* parent)
: DBlurEffectWidget(parent)
{
setMaskAlpha(200);
setBlendMode(DBlurEffectWidget::BehindWindowBlend);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
initWidgets();
setMinimumSize(QSize(320, 320));
move(QCursor::pos());
}
void StickyWidget::initWidgets()
{
auto mainLayout = new QStackedLayout(this);
mainLayout->setStackingMode(QStackedLayout::StackAll);
auto topLayer = new TransparentWidget(this);
auto topLayout = new QVBoxLayout(topLayer);
auto bottomLayer = new QWidget(this);
auto bottomLayout = new QVBoxLayout(bottomLayer);
editor = new ZTextEdit(this, false);
{ // init editor
editor->viewport()->setAttribute(Qt::WA_TranslucentBackground);
editor->setTopMargin(20);
editor->setBottomMargin(50);
}
auto titleBarLayout = new QHBoxLayout(topLayer);
{ // init titlebar
auto attachButton = new DIconButton(this);
attachButton->setFlat(true);
attachButton->setIcon(QIcon(":/images/attach"));
attachButton->setIconSize(QSize(25, 30));
connect(attachButton, &DIconButton::clicked, [this]() {
Daemon::instance()->toggleAttach(noteIndex());
this->hide();
this->deleteLater();
});
titleBarLayout->addStretch();
titleBarLayout->addWidget(attachButton);
}
auto toolBarLayout = new QHBoxLayout(topLayer);
{ // init toolbar
toolBarLayout->addStretch();
toolBarLayout->addWidget(initToolBar(topLayer, editor));
toolBarLayout->addStretch();
}
topLayout->setContentsMargins(0, 0, 0, 0);
topLayout->addLayout(titleBarLayout);
topLayout->addStretch();
topLayout->addLayout(toolBarLayout);
topLayer->setLayout(topLayout);
// bottomLayout->addSpacing(10);
bottomLayout->addWidget(editor);
bottomLayer->setLayout(bottomLayout);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(topLayer);
mainLayout->addWidget(bottomLayer);
setLayout(mainLayout);
setContentsMargins(0, 0, 0, 0);
}
QWidget* StickyWidget::initToolBar(QWidget* parent, ZTextEdit* textEditor)
{
auto bar = new RoundedWidget(parent, 15, RoundedWidget::TopTwo, QPoint(0, 5));
bar->setShadow(5);
auto layout = new QHBoxLayout(bar);
auto bold = new CircleButton(QIcon(":/images/font-bold"), bar), italic = new CircleButton(QIcon(":/images/font-italic"), bar),
underline = new CircleButton(QIcon(":/images/font-underline"), bar),
linethrough = new CircleButton(QIcon(":/images/font-linethrough"), bar),
image = new CircleButton(QIcon(":/images/insimage"), bar);
for (auto i : { bold, italic, underline, linethrough }) {
i->setCheckable(true);
}
connect(bold, &QPushButton::toggled, textEditor, &ZTextEdit::fBold);
connect(textEditor, &ZTextEdit::fBoldState, bold, &QPushButton::setChecked);
connect(italic, &QPushButton::toggled, textEditor, &ZTextEdit::fItalic);
connect(textEditor, &ZTextEdit::fItalicState, italic, &QPushButton::setChecked);
connect(underline, &QPushButton::toggled, textEditor, &ZTextEdit::fUnderline);
connect(textEditor, &ZTextEdit::fUnderlineState, underline, &QPushButton::setChecked);
connect(linethrough, &QPushButton::toggled, textEditor, &ZTextEdit::fLinethrough);
connect(textEditor, &ZTextEdit::fLinethroughState, linethrough, &QPushButton::setChecked);
connect(image, &QPushButton::clicked, textEditor, &ZTextEdit::pInsImage);
auto newAction = [this](QKeySequence shortcut, bool b = true) {
auto rt = new QAction;
rt->setCheckable(b);
rt->setShortcut(shortcut);
this->addAction(rt);
return rt;
};
connect(newAction(QKeySequence::Bold), &QAction::toggled, textEditor, &ZTextEdit::fBold);
connect(newAction(QKeySequence::Underline), &QAction::toggled, textEditor, &ZTextEdit::fUnderline);
connect(newAction(QKeySequence::Italic), &QAction::toggled, textEditor, &ZTextEdit::fItalic);
layout->addWidget(bold), layout->addWidget(italic), layout->addWidget(underline), layout->addWidget(linethrough),
layout->addWidget(image);
bar->setLayout(layout);
return bar;
}
/*void StickyWidget::focusOutEvent(QFocusEvent *e)
{
commitChange(note);
}*/