-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaddialog.cpp
More file actions
146 lines (119 loc) · 4.91 KB
/
Copy pathheaddialog.cpp
File metadata and controls
146 lines (119 loc) · 4.91 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
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
#include "headdialog.h"
#include "ui_headdialog.h"
//#include "mainwindow.h"
#include "gcalc.h"
//#include "tools.h"
#include <QIntValidator>
#include <QStringList>
#include <QFile>
#include <QDebug>
#include <QTextStream>
headDialog::headDialog(const QString &filename, const QString &label, QWidget *parent)
: QDialog(parent), ui(new Ui::headDialog), _filename(filename), _label(label)
{
ui->setupUi(this);
this->setWindowTitle("News Headlines - " + _label);
QString nightm = readSettings("settings.txt", "nightmode");
bool nightmode = (nightm == "1" || nightm.toLower() == "true");
if (nightmode) {
this->setStyleSheet("background-color: #1a1a1a; color: lightgray;");
ui->textBrowser->setStyleSheet("background-color: #1a1a1a; color: lightgray; border: 1px solid #333;");
ui->lineEdit->setStyleSheet("background-color: #2a2a2a; color: white; border: 1px solid #555;");
ui->current_url->setStyleSheet("color: lightgray;");
ui->SaveNewsFilter->setStyleSheet("background-color: #333333; color: white; border: 1px solid #444;");
ui->ajustinput->setStyleSheet("background-color: #333333; color: white;");
ui->label_2->setStyleSheet("color: lightgray;");
ui->numberofchar->setStyleSheet("color: lightgray;");
ui->englisordinal->setStyleSheet("color: lightgray;");
ui->fullreduction->setStyleSheet("color: lightgray;");
ui->reverseordinal->setStyleSheet("color: lightgray;");
ui->reversefull->setStyleSheet("color: lightgray;");
ui->textBrowser->setStyleSheet(
"QTextBrowser { background-color: #1a1a1a; color: lightgrey; }"
"a { color: grey; text-decoration: none; }"
"a:hover { text-decoration: underline; }"
);
}
// 2. Also override the palette (in case system settings are enforced)
QPalette p = ui->textBrowser->palette();
p.setColor(QPalette::Link, QColor("grey"));
p.setColor(QPalette::Text, QColor("lightgrey"));
ui->textBrowser->setPalette(p);
ui->textBrowser->setOpenExternalLinks(true);
ui->textBrowser->setTextInteractionFlags(Qt::TextBrowserInteraction);
ui->current_url->setText(_label);
List = getheadlines(_filename, 20);
ui->lineEdit->setValidator(new QIntValidator(0, 9999, this));
ui->lineEdit->setFocus();
ui->lineEdit->clear();
for (const auto &i : List) {
ui->textBrowser->append(i);
}
ui->SaveNewsFilter->hide();
ui->ajustinput->setDisabled(true);
ui->label_2->hide();
ui->numberofchar->hide();
}
void headDialog::on_lineEdit_returnPressed()
{
QStringList filterlist, displaylist;
QString nstype;
int nslist = ui->lineEdit->text().toUInt(), count, startw, endw, red = 0, rev = 0;
if (ui->englisordinal->isChecked()) nstype = "English Ordinal";
if (ui->fullreduction->isChecked()) { red = 1; nstype = "Full Reduction"; }
if (ui->reverseordinal->isChecked()) { rev = 1; nstype = "Reverse Ordinal"; }
if (ui->reversefull->isChecked()) { red = 1; rev = 1; nstype = "Reverse Full Reduction"; }
for (const auto& i : List) {
if (i.trimmed().isEmpty()) continue;
filterlist = i.split(" ");
QVector<int> sum;
for (const auto& l : filterlist)
sum.append(getwordnumericvalue(l.toUtf8().constData(), red, rev, 0));
bool found = false;
int result = 0, c = 0, loops = 0;
startw = endw = -1;
while (!found && loops < sum.size()) {
result += sum[c];
if (result == nslist) {
found = true;
startw = loops;
endw = c;
}
if (c >= sum.size() - 1 || result > nslist) {
result = 0;
loops++;
c = loops;
} else if (!found) c++;
}
if (!found) {
displaylist << i;
} else {
QString formatted;
for (int j = 0; j < filterlist.size(); ++j) {
if (j >= startw && j <= endw && sum[j] != 0)
formatted += Qformattext(filterlist[j].toUtf8().constData(), 2, 1) + " ";
else
formatted += filterlist[j] + " ";
}
displaylist << formatted.trimmed() + " - " + nstype + ": " + Qformattext(QString::number(nslist).toUtf8().constData(), 1, 1);
}
}
ui->textBrowser->clear();
for (const auto& i : displaylist)
ui->textBrowser->append(i);
}
void headDialog::on_englisordinal_toggled(bool checked) {
if (checked) emit on_lineEdit_returnPressed();
}
void headDialog::on_fullreduction_toggled(bool checked) {
if (checked) emit on_lineEdit_returnPressed();
}
void headDialog::on_reverseordinal_toggled(bool checked) {
if (checked) emit on_lineEdit_returnPressed();
}
void headDialog::on_reversefull_toggled(bool checked) {
if (checked) emit on_lineEdit_returnPressed();
}
headDialog::~headDialog() {
delete ui;
}