-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheditcomments.cpp
More file actions
120 lines (109 loc) · 3.38 KB
/
editcomments.cpp
File metadata and controls
120 lines (109 loc) · 3.38 KB
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
112
113
114
115
116
117
118
119
120
#include <QtGui>
#include "editcomments.h"
#include "configuration.h"
#include <QTextEdit>
#include <QLineEdit>
#include <QDialogButtonBox>
#include <QMenuBar>
#include <QMenu>
#include <QGroupBox>
#include <QPushButton>
EditComments::EditComments()
{
createMenu();
createHorizontalGroupBox();
txtEdit = new QTextEdit;
txtTags = new QLineEdit;
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setMenuBar((QWidget*)menuBar);
mainLayout->addWidget((QWidget*)horizontalGroupBox);
mainLayout->addWidget(txtEdit);
mainLayout->addWidget(txtTags);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
connect(txtEdit, SIGNAL(selectionChanged()), this, SLOT(OnSelectionChanged()));
setWindowTitle(tr("Edit Comments"));
}
void EditComments::createMenu()
{
menuBar = new QMenuBar();
fileMenu = new QMenu(tr("&File"), this);
exitAction = fileMenu->addAction(tr("E&xit"));
menuBar->addMenu(fileMenu);
connect(exitAction, SIGNAL(triggered()), this, SLOT(accept()));
formatMenu = new QMenu(tr("Format"), this);
boldAction = formatMenu->addAction(tr("Bold"));
boldAction->setCheckable(true);
italicAction =formatMenu->addAction(tr("Italicize"));
italicAction->setCheckable(true);
underlineAct = formatMenu->addAction(tr("Underline"));
underlineAct->setCheckable(true);
menuBar->addMenu(formatMenu);
connect(boldAction, SIGNAL(triggered(bool)), this, SLOT(OnBoldAction(bool)));
connect(italicAction, SIGNAL(triggered(bool)), this, SLOT(OnItalicAction(bool)));
connect(underlineAct, SIGNAL(triggered(bool)), this, SLOT(OnUnderlineAct(bool)));
}
void EditComments::createHorizontalGroupBox()
{
horizontalGroupBox = new QGroupBox(tr("Horizontal layout"));
QHBoxLayout *layout = new QHBoxLayout;
for (int i = 0; i < 3; ++i) {
buttons[i] = new QPushButton(tr("Button %1").arg(i + 1));
layout->addWidget(buttons[i]);
}
horizontalGroupBox->setLayout(layout);
}
void EditComments::setConfiguration(Configuration *cfg)
{
config = cfg;
}
void EditComments::setHTMLText(QString html)
{
txtEdit->setHtml(html);
}
void EditComments::setTags(QString tags)
{
txtTags->setText( tags);
}
QString EditComments::HTML()
{
QString str = txtEdit->toHtml();
//qint32 count = str.length();
return str;
}
QString EditComments::Tags()
{
return txtTags->text();
}
void EditComments::OnBoldAction(bool checked)
{
QTextCursor cur = txtEdit->textCursor();
if(checked)
txtEdit->setFontWeight(75);
else
txtEdit->setFontWeight(50);
boldAction->setChecked(!checked);
}
void EditComments::OnItalicAction(bool checked)
{
QTextCursor cur = txtEdit->textCursor();
txtEdit->setFontItalic(!checked);
italicAction->setChecked(!checked);
}
void EditComments::OnUnderlineAct(bool checked)
{
txtEdit->setFontUnderline(!checked);
underlineAct->setChecked(!checked);
}
void EditComments::OnSelectionChanged()
{
if(txtEdit->fontWeight()< 75)
boldAction->setChecked(false);
else
boldAction->setChecked(true);
italicAction->setChecked(txtEdit->fontItalic());
underlineAct->setChecked(txtEdit->fontUnderline());
}