File: ReplaceWin.cpp

package info (click to toggle)
basic256 0.9.6.69a-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,304 kB
  • sloc: cpp: 7,778; yacc: 926; lex: 575; sh: 21; makefile: 7
file content (117 lines) | stat: -rw-r--r-- 4,079 bytes parent folder | download
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
/** Copyright (C) 2010, J.M.Reneau
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License as published by
 **  the Free Software Foundation; either version 2 of the License, or
 **  (at your option) any later version.
 **
 **  This program is distributed in the hope that it will be useful,
 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 **  GNU General Public License for more details.
 **
 **  You should have received a copy of the GNU General Public License along
 **  with this program; if not, write to the Free Software Foundation, Inc.,
 **  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 **/

#include <iostream>

using namespace std;

#include "ReplaceWin.h"
#include "Settings.h"
#include "MainWindow.h"
#include "md5.h"

ReplaceWin::ReplaceWin (QWidget * parent)
{

	// parent must be basicedit
	be = (BasicEdit *) parent;

	// position where it was last on screen
	QSettings settings(SETTINGSORG, SETTINGSAPP);
	move(settings.value(SETTINGSFINDPOS, QPoint(200, 200)).toPoint());
	setWindowTitle(tr("BASIC-256 Replace"));

	QGridLayout * layout = new QGridLayout();
	int r=0;

	fromlabel = new QLabel(tr("From:"),this);
	layout->addWidget(fromlabel,r,1,1,1);
	frominput = new QLineEdit(settings.value(SETTINGSREPLACEFROM, "").toString());
	frominput->setMaxLength(100);
	connect(frominput, SIGNAL(textChanged(QString)), this, SLOT (changeFromInput(QString)));
	layout->addWidget(frominput,r,2,1,3);
	//
	r++;
	tolabel = new QLabel(tr("To:"),this);
	layout->addWidget(tolabel,r,1,1,1);
	toinput = new QLineEdit(settings.value(SETTINGSREPLACETO, "").toString());
	toinput->setMaxLength(100);
	layout->addWidget(toinput,r,2,1,3);
	//
	r++;
	casecheckbox = new QCheckBox(tr("Case Sensitive"),this);
	casecheckbox->setChecked(settings.value(SETTINGSREPLACECASE, SETTINGSREPLACECASEDEFAULT).toBool());
	layout->addWidget(casecheckbox,r,2,1,3);
	//
	r++;
	cancelbutton = new QPushButton(tr("Cancel"), this);
	connect(cancelbutton, SIGNAL(clicked()), this, SLOT (clickCancelButton()));
	layout->addWidget(cancelbutton,r,1,1,1);
	replaceallbutton = new QPushButton(tr("Replace All"), this);
	connect(replaceallbutton, SIGNAL(clicked()), this, SLOT (clickReplaceAllButton()));
	layout->addWidget(replaceallbutton,r,2,1,1);
	replacebutton = new QPushButton(tr("Replace"), this);
	connect(replacebutton, SIGNAL(clicked()), this, SLOT (clickReplaceButton()));
	layout->addWidget(replacebutton,r,3,1,1);
	findbutton = new QPushButton(tr("Find"), this);
	connect(findbutton, SIGNAL(clicked()), this, SLOT (clickFindButton()));
	layout->addWidget(findbutton,r,4,1,1);
	//
	this->setLayout(layout);
	this->show();
	changeFromInput(frominput->text());
}

void ReplaceWin::changeFromInput(QString t) {
		replacebutton->setEnabled((t.length() != 0) && (t.compare(be->textCursor().selectedText(),(casecheckbox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive))==0));
		replaceallbutton->setEnabled(t.length() != 0);
		findbutton->setEnabled(t.length() != 0);
}

void ReplaceWin::clickCancelButton() {
	close();
}

void ReplaceWin::clickFindButton() {
	saveSettings();
	be->findString(frominput->text(), false, casecheckbox->isChecked());
	changeFromInput(frominput->text());
}

void ReplaceWin::clickReplaceButton() {
	saveSettings();
	be->replaceString(frominput->text(), toinput->text(), casecheckbox->isChecked(), false);
	changeFromInput(frominput->text());
}

void ReplaceWin::clickReplaceAllButton() {
	saveSettings();
	be->replaceString(frominput->text(), toinput->text(), casecheckbox->isChecked(), true);
}

void ReplaceWin::closeEvent(QCloseEvent *e) {
	saveSettings();
}

void ReplaceWin::saveSettings() {
	QSettings settings(SETTINGSORG, SETTINGSAPP);
	settings.setValue(SETTINGSREPLACEPOS, pos());
	settings.setValue(SETTINGSREPLACEFROM, frominput->text());
	settings.setValue(SETTINGSREPLACETO, toinput->text());
	settings.setValue(SETTINGSREPLACECASE, casecheckbox->isChecked());
}