Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fb2dlgs.cpp « source - github.com/lintest/fb2edit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f06c2ff570ace8cf19896fbd650dd68d7734cf25 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "fb2dlgs.hpp"
#include "fb2code.hpp"
#include "fb2page.hpp"
#include "fb2text.hpp"
#include "fb2tree.hpp"
#include "fb2utils.h"
#include "ui_fb2find.h"
#include "ui_fb2setup.h"

#include <QComboBox>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QFrame>
#include <QLabel>
#include <QLineEdit>
#include <QTabWidget>
#include <QToolBar>
#include <QWebFrame>
#include <QWebPage>

//---------------------------------------------------------------------------
//  FbCodeFindDlg
//---------------------------------------------------------------------------

FbCodeFindDlg::FbCodeFindDlg(FbCodeEdit &edit)
    : QDialog(&edit)
    , ui(new Ui::FbFind)
    , m_edit(edit)
{
    ui->setupUi(this);
    ui->checkHigh->setText(tr("Complete words"));
    connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
}

FbCodeFindDlg::~FbCodeFindDlg()
{
    delete ui;
}

void FbCodeFindDlg::find()
{
    QString text = ui->editText->text();
    if (text.isEmpty()) return;
    QTextDocument::FindFlags options = 0;
    if (ui->radioUp->isChecked()) options |= QTextDocument::FindBackward;
    if (ui->checkCase->isChecked()) options |= QTextDocument::FindCaseSensitively;
    if (ui->checkHigh->isChecked()) options |= QTextDocument::FindWholeWords;

    m_edit.findText(text, options);
}

//---------------------------------------------------------------------------
//  FbTextFindDlg
//---------------------------------------------------------------------------

FbTextFindDlg::FbTextFindDlg(FbTextEdit &edit)
    : QDialog(&edit)
    , ui(new Ui::FbFind)
    , m_edit(edit)
{
    ui->setupUi(this);
    ui->checkHigh->hide();
    connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
}

FbTextFindDlg::~FbTextFindDlg()
{
    m_edit.findText(QString(), QWebPage::HighlightAllOccurrences);
    delete ui;
}

void FbTextFindDlg::find()
{
    QString text = ui->editText->text();
    if (text.isEmpty()) return;
    QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
    if (ui->radioUp->isChecked()) options |= QWebPage::FindBackward;
    if (ui->checkCase->isChecked()) options |= QWebPage::FindCaseSensitively;
    m_edit.findText(text, options);

    options |= QWebPage::HighlightAllOccurrences;
    m_edit.findText(text, options);
}

//---------------------------------------------------------------------------
//  FbNoteDlg
//---------------------------------------------------------------------------

FbNoteDlg::FbNoteDlg(FbTextEdit &view)
    : QDialog(&view)
{
    setWindowTitle(tr("Insert footnote"));
    resize(460, 300);

    QGridLayout * gridLayout = new QGridLayout(this);

    QLabel * label1 = new QLabel(this);
    label1->setText(tr("Identifier:"));
    gridLayout->addWidget(label1, 0, 0, 1, 1);

    m_key = new QComboBox(this);
    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    gridLayout->addWidget(m_key, 0, 1, 1, 1);

    QLabel * label2 = new QLabel(this);
    label2->setText(tr("Title:"));
    gridLayout->addWidget(label2, 1, 0, 1, 1);

    m_title = new QLineEdit(this);
    m_title->setObjectName(QString::fromUtf8("m_title"));
    gridLayout->addWidget(m_title, 1, 1, 1, 1);

    m_toolbar = new QToolBar(this);
    gridLayout->addWidget(m_toolbar, 2, 0, 1, 2);

    QFrame * frame = new QFrame(this);
    frame->setFrameShape(QFrame::StyledPanel);
    frame->setFrameShadow(QFrame::Sunken);
    gridLayout->addWidget(frame, 3, 0, 1, 2);

    QLayout * frameLayout = new QBoxLayout(QBoxLayout::LeftToRight, frame);
    frameLayout->setSpacing(0);
    frameLayout->setMargin(0);

    m_text = new FbTextBase(frame);
    m_text->setObjectName(QString::fromUtf8("m_text"));
    m_text->setUrl(QUrl(QString::fromUtf8("about:blank")));
    frameLayout->addWidget(m_text);

    QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
    buttonBox->setOrientation(Qt::Horizontal);
    buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
    gridLayout->addWidget(buttonBox, 4, 0, 1, 2);

    QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

    m_key->addItem(tr("<create new>"));
    m_key->setCurrentIndex(0);
    m_title->setFocus();

    FbTextPage *page = new FbTextPage(this);
    connect(m_text, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
    page->setNetworkAccessManager(view.page()->networkAccessManager());
    page->setContentEditable(true);
    m_text->setPage(page);
    m_text->setHtml("<body><p><br></p></body>");

    m_text->addTools(m_toolbar);
}

void FbNoteDlg::loadFinished()
{
    FbTextElement body = m_text->page()->mainFrame()->documentElement().findFirst("body");
    body.select();
}

//---------------------------------------------------------------------------
//  FbSetupDlg
//---------------------------------------------------------------------------

FbSetupDlg::FbSetupDlg(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::FbSetup)
{
    ui->setupUi(this);
}

//---------------------------------------------------------------------------
//  FbImageDlg::FbTab
//---------------------------------------------------------------------------

FbImageDlg::FbTab::FbTab(QWidget* parent)
    : QWidget(parent)
{
    QGridLayout * layout = new QGridLayout(this);

    label = new QLabel(this);
    label->setText(tr("File name:"));
    layout->addWidget(label, 0, 0, 1, 1);

    combo = new FbImageCombo(this);
    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    combo->setSizePolicy(sizePolicy);
    layout->addWidget(combo, 0, 1, 1, 1);

    QFrame *frame = new FbTextFrame(this);
    frame->setMinimumSize(QSize(300, 200));
    layout->addWidget(frame, 1, 0, 1, 2);

    preview = new QWebView(this);
    frame->layout()->addWidget(preview);
}

//---------------------------------------------------------------------------
//  FbImageCombo
//---------------------------------------------------------------------------

void FbImageCombo::showPopup()
{
    QComboBox::showPopup();
    if (isEditable()) {
        emit popup();
        QComboBox::hidePopup();
    }
}

void FbImageCombo::selectFile()
{
    QString filters;
    filters += tr("Common Graphics (*.png *.jpg *.jpeg *.gif)") += ";;";
    filters += tr("Portable Network Graphics (PNG) (*.png)") += ";;";
    filters += tr("JPEG (*.jpg *.jpeg)") += ";;";
    filters += tr("Graphics Interchange Format (*.gif)") += ";;";
    filters += tr("All Files (*)");

    QString path = QFileDialog::getOpenFileName(this, tr("Insert image..."), QString(), filters);
    if (!path.isEmpty()) setEditText(path);
}

//---------------------------------------------------------------------------
//  FbImageDlg
//---------------------------------------------------------------------------

FbImageDlg::FbImageDlg(FbTextEdit *text)
    : QDialog(text)
    , tabFile(0)
    , tabPict(0)
{
    setWindowTitle(tr("Insert picture"));

    QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);

    notebook = new QTabWidget(this);
    layout->addWidget(notebook);

    QDialogButtonBox *buttons = new QDialogButtonBox(this);
    buttons->setOrientation(Qt::Horizontal);
    buttons->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
    layout->addWidget(buttons);

    connect(buttons, SIGNAL(accepted()), SLOT(accept()));
    connect(buttons, SIGNAL(rejected()), SLOT(reject()));
    connect(notebook, SIGNAL(currentChanged(int)), SLOT(notebookChanged(int)));

    QUrl url = text->url();

    tabFile = new FbTab(notebook);
    tabFile->combo->setEditable(true);
    tabFile->preview->setHtml(QString(), url);
    connect(tabFile->combo, SIGNAL(popup()), tabFile->combo, SLOT(selectFile()));
    notebook->addTab(tabFile, tr("Select file"));

    if (text->store()->count()) {
        FbListModel *model = new FbListModel(text, this);
        tabPict = new FbTab(notebook);
        tabPict->preview->setHtml(QString(), url);
        tabPict->combo->setModel(model);
        tabPict->combo->setCurrentIndex(0);
        tabPict->preview->page()->setNetworkAccessManager(text->page()->networkAccessManager());
        notebook->addTab(tabPict, tr("From collection"));
        connect(tabPict->combo, SIGNAL(activated(QString)), SLOT(pictureActivated(QString)));
        tabPict->combo->setFocus();
    }

    QString style =
//      "QComboBox::drop-down{border:0px;margin:0px;}"
        "QComboBox::down-arrow{image:url(:dots.png);}";
    tabFile->combo->setStyleSheet(style);

    tabFile->combo->setFocus();
    resize(minimumSizeHint());
}

void FbImageDlg::notebookChanged(int index)
{
    if (index) {
        disconnect(notebook, SIGNAL(currentChanged(int)), this, SLOT(notebookChanged(int)));
        if (tabPict) pictureActivated(tabPict->combo->itemText(0));
    }
}

void FbImageDlg::pictureActivated(const QString & text)
{
    QUrl url = tabPict->preview->url();
    url.setFragment(text);
    QString html = QString("<img src=%1 valign=center align=center width=100%>").arg(url.toString());
    tabPict->preview->setHtml(html, tabPict->preview->url());
}