summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/cgotobase.ui65
-rw-r--r--noncore/apps/tinykate/cgotoline.cpp23
-rw-r--r--noncore/apps/tinykate/cgotoline.h10
-rw-r--r--noncore/apps/tinykate/libkate/document/katebuffer.cpp2
-rw-r--r--noncore/apps/tinykate/libkate/libkate.pro12
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kcolordialog.cpp6
-rw-r--r--noncore/apps/tinykate/libkate/microkde/qcolordialog.cpp1631
-rw-r--r--noncore/apps/tinykate/libkate/microkde/qcolordialog.h84
-rw-r--r--noncore/apps/tinykate/libkate/microkde/xmltree.cc322
-rw-r--r--noncore/apps/tinykate/libkate/microkde/xmltree.h117
-rw-r--r--noncore/apps/tinykate/libkate/view/kateview.cpp16
-rw-r--r--noncore/apps/tinykate/tinykate.cpp157
-rw-r--r--noncore/apps/tinykate/tinykate.h24
-rw-r--r--noncore/apps/tinykate/tinykate.pro22
14 files changed, 2398 insertions, 93 deletions
diff --git a/noncore/apps/tinykate/cgotobase.ui b/noncore/apps/tinykate/cgotobase.ui
new file mode 100644
index 0000000..6660cb8
--- a/dev/null
+++ b/noncore/apps/tinykate/cgotobase.ui
@@ -0,0 +1,65 @@
1<!DOCTYPE UI><UI>
2<class>CGotoBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>CGotoBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>215</width>
15 <height>50</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Goto Line</string>
21 </property>
22 <hbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QLabel</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>TextLabel1</cstring>
36 </property>
37 <property stdset="1">
38 <name>sizePolicy</name>
39 <sizepolicy>
40 <hsizetype>0</hsizetype>
41 <vsizetype>1</vsizetype>
42 </sizepolicy>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>Line:</string>
47 </property>
48 <property stdset="1">
49 <name>alignment</name>
50 <set>AlignVCenter|AlignRight</set>
51 </property>
52 <property>
53 <name>hAlign</name>
54 </property>
55 </widget>
56 <widget>
57 <class>QSpinBox</class>
58 <property stdset="1">
59 <name>name</name>
60 <cstring>mLine</cstring>
61 </property>
62 </widget>
63 </hbox>
64</widget>
65</UI>
diff --git a/noncore/apps/tinykate/cgotoline.cpp b/noncore/apps/tinykate/cgotoline.cpp
new file mode 100644
index 0000000..97f2ea5
--- a/dev/null
+++ b/noncore/apps/tinykate/cgotoline.cpp
@@ -0,0 +1,23 @@
1#include "cgotoline.h"
2#include <qspinbox.h>
3// copyright 2003 Craig Graham <cgraham@accessdevices.co.uk>
4
5CGotoLine::CGotoLine(int l) : CGotoBase(0,0,true)
6{
7 mLine->setValue(l+1);
8}
9
10int CGotoLine::line()
11{
12 return mLine->value()-1;
13}
14
15void CGotoLine::keyPressEvent(QKeyEvent *e)
16{
17 if((e->key()==Key_Return)||(e->key()==Key_Enter))
18 {
19 accept();
20 }else{
21 QDialog::keyPressEvent(e);
22 }
23}
diff --git a/noncore/apps/tinykate/cgotoline.h b/noncore/apps/tinykate/cgotoline.h
new file mode 100644
index 0000000..29d6f42
--- a/dev/null
+++ b/noncore/apps/tinykate/cgotoline.h
@@ -0,0 +1,10 @@
1//
2// copyright 2003 Craig Graham <cgraham@accessdevices.co.uk>
3#include "cgotobase.h"
4class CGotoLine : public CGotoBase {
5public:
6 CGotoLine(int line);
7 int line();
8protected:
9 virtual void keyPressEvent(QKeyEvent *e);
10};
diff --git a/noncore/apps/tinykate/libkate/document/katebuffer.cpp b/noncore/apps/tinykate/libkate/document/katebuffer.cpp
index 22a4917..38ba55d 100644
--- a/noncore/apps/tinykate/libkate/document/katebuffer.cpp
+++ b/noncore/apps/tinykate/libkate/document/katebuffer.cpp
@@ -1,179 +1,179 @@
1/* 1/*
2 This file is part of KWrite 2 This file is part of KWrite
3 Copyright (c) 2000 Waldo Bastian <bastian@kde.org> 3 Copyright (c) 2000 Waldo Bastian <bastian@kde.org>
4 Copyright (c) 2002 Joseph Wenninger <jowenn@kde.org> 4 Copyright (c) 2002 Joseph Wenninger <jowenn@kde.org>
5 5
6 $Id$ 6 $Id$
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License version 2 as published by the Free Software Foundation. 10 License version 2 as published by the Free Software Foundation.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23 23
24#include "katebuffer.h" 24#include "katebuffer.h"
25 25
26// Includes for reading file 26// Includes for reading file
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <fcntl.h> 29#include <fcntl.h>
30#include <errno.h> 30#include <errno.h>
31#include <unistd.h> 31#include <unistd.h>
32 32
33#include <qfile.h> 33#include <qfile.h>
34#include <qtextstream.h> 34#include <qtextstream.h>
35 35
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qtextcodec.h> 37#include <qtextcodec.h>
38 38
39// 39//
40 40
41#include <assert.h> 41#include <assert.h>
42#include <kdebug.h> 42#include <kdebug.h>
43 43
44/** 44/**
45 * Create an empty buffer. 45 * Create an empty buffer.
46 */ 46 */
47KWBuffer::KWBuffer() 47KWBuffer::KWBuffer()
48{ 48{
49 clear(); 49 clear();
50} 50}
51 51
52void 52void
53KWBuffer::clear() 53KWBuffer::clear()
54{ 54{
55 m_stringListIt=0; 55 m_stringListIt=0;
56 m_stringListCurrent=0; 56 m_stringListCurrent=0;
57 m_stringList.clear(); 57 m_stringList.clear();
58 m_lineCount=1; 58 m_lineCount=1;
59 m_stringListIt = m_stringList.append(new TextLine()); 59 m_stringListIt = m_stringList.append(new TextLine());
60} 60}
61 61
62/** 62/**
63 * Insert a file at line @p line in the buffer. 63 * Insert a file at line @p line in the buffer.
64 */ 64 */
65void 65void
66KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) 66KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec)
67{ 67{
68 if (line) { 68 if (line) {
69 qDebug("insert File only supports insertion at line 0 == file opening"); 69 qDebug("insert File only supports insertion at line 0 == file opening");
70 return; 70 return;
71 } 71 }
72 clear(); 72 clear();
73 QFile iofile(file); 73 QFile iofile(file);
74 iofile.open(IO_ReadOnly); 74 iofile.open(IO_ReadOnly);
75 QTextStream stream(&iofile); 75 QTextStream stream(&iofile);
76 stream.setCodec(codec); 76 stream.setCodec(codec);
77 QString qsl; 77 QString qsl;
78 int count=0; 78 int count=0;
79 for (count=0;((qsl=stream.readLine())!=QString::null);count++) 79 for (count=0;((qsl=stream.readLine())!=QString::null);count++)
80 { 80 {
81 if (count==0) 81 if (count==0)
82 { 82 {
83 (*m_stringListIt)->append(qsl.unicode(),qsl.length()); 83 (*m_stringListIt)->append(qsl.unicode(),qsl.length());
84 } 84 }
85 else 85 else
86 { 86 {
87 TextLine::Ptr tl=new TextLine(); 87 TextLine::Ptr tl=new TextLine();
88 tl ->append(qsl.unicode(),qsl.length()); 88 tl ->append(qsl.unicode(),qsl.length());
89 m_stringListIt=m_stringList.append(tl); 89 m_stringListIt=m_stringList.append(tl);
90 } 90 }
91 } 91 }
92 if (count!=0) 92 if (count!=0)
93 { 93 {
94 m_stringListCurrent=count-1; 94 m_stringListCurrent=count-1;
95 m_lineCount=count; 95 m_lineCount=count;
96 } 96 }
97} 97}
98 98
99void 99void
100KWBuffer::loadFilePart() 100KWBuffer::loadFilePart()
101{ 101{
102} 102}
103 103
104 104
105void 105void
106KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) 106KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec)
107{ 107{
108} 108}
109 109
110void 110void
111KWBuffer::slotLoadFile() 111KWBuffer::slotLoadFile()
112{ 112{
113 loadFilePart(); 113 loadFilePart();
114// emit linesChanged(m_totalLines); 114// emit linesChanged(m_totalLines);
115 emit linesChanged(20); 115 emit linesChanged(20);
116} 116}
117 117
118/** 118/**
119 * Return the total number of lines in the buffer. 119 * Return the total number of lines in the buffer.
120 */ 120 */
121int 121int
122KWBuffer::count() 122KWBuffer::count()
123{ 123{
124 qDebug("m_stringList.count %d",m_stringList.count()); 124// qDebug("m_stringList.count %d",m_stringList.count());
125 return m_lineCount; 125 return m_lineCount;
126 //return m_stringList.count(); 126 //return m_stringList.count();
127// return m_totalLines; 127// return m_totalLines;
128} 128}
129 129
130 130
131void KWBuffer::seek(int i) 131void KWBuffer::seek(int i)
132{ 132{
133 if (m_stringListCurrent == i) 133 if (m_stringListCurrent == i)
134 return; 134 return;
135 while(m_stringListCurrent < i) 135 while(m_stringListCurrent < i)
136 { 136 {
137 ++m_stringListCurrent; 137 ++m_stringListCurrent;
138 ++m_stringListIt; 138 ++m_stringListIt;
139 } 139 }
140 while(m_stringListCurrent > i) 140 while(m_stringListCurrent > i)
141 { 141 {
142 --m_stringListCurrent; 142 --m_stringListCurrent;
143 --m_stringListIt; 143 --m_stringListIt;
144 } 144 }
145} 145}
146 146
147 147
148TextLine::Ptr 148TextLine::Ptr
149KWBuffer::line(int i) 149KWBuffer::line(int i)
150{ 150{
151 if (i>=m_stringList.count()) return 0; 151 if (i>=m_stringList.count()) return 0;
152 seek(i); 152 seek(i);
153 return *m_stringListIt; 153 return *m_stringListIt;
154} 154}
155 155
156void 156void
157KWBuffer::insertLine(int i, TextLine::Ptr line) 157KWBuffer::insertLine(int i, TextLine::Ptr line)
158{ 158{
159 seek(i); 159 seek(i);
160 m_stringListIt = m_stringList.insert(m_stringListIt, line); 160 m_stringListIt = m_stringList.insert(m_stringListIt, line);
161 m_stringListCurrent = i; 161 m_stringListCurrent = i;
162 m_lineCount++; 162 m_lineCount++;
163} 163}
164 164
165 165
166void 166void
167KWBuffer::removeLine(int i) 167KWBuffer::removeLine(int i)
168{ 168{
169 seek(i); 169 seek(i);
170 m_stringListIt = m_stringList.remove(m_stringListIt); 170 m_stringListIt = m_stringList.remove(m_stringListIt);
171 m_stringListCurrent = i; 171 m_stringListCurrent = i;
172 m_lineCount--; 172 m_lineCount--;
173} 173}
174 174
175void 175void
176KWBuffer::changeLine(int i) 176KWBuffer::changeLine(int i)
177{ 177{
178} 178}
179 179
diff --git a/noncore/apps/tinykate/libkate/libkate.pro b/noncore/apps/tinykate/libkate/libkate.pro
index 0082106..2fcced7 100644
--- a/noncore/apps/tinykate/libkate/libkate.pro
+++ b/noncore/apps/tinykate/libkate/libkate.pro
@@ -1,91 +1,91 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 HEADERS = microkde/kapplication.h \ 3 HEADERS = microkde/kapplication.h \
4 kateconfig.h \ 4 kateconfig.h \
5 microkde/kdebug.h \ 5 microkde/kdebug.h \
6 microkde/kdialog.h \ 6 microkde/kdialog.h \
7 microkde/kdialogbase.h \ 7 microkde/kdialogbase.h \
8 microkde/kfiledialog.h \ 8 microkde/kfiledialog.h \
9 microkde/kglobal.h \ 9 microkde/kglobal.h \
10 microkde/kiconloader.h \ 10 microkde/kiconloader.h \
11 microkde/klineedit.h \ 11 microkde/klineedit.h \
12 microkde/klocale.h \ 12 microkde/klocale.h \
13 microkde/kmessagebox.h \ 13 microkde/kmessagebox.h \
14 microkde/kprinter.h \ 14 microkde/kprinter.h \
15 microkde/krestrictedline.h \ 15 microkde/krestrictedline.h \
16 microkde/kseparator.h \ 16 microkde/kseparator.h \
17 microkde/kstandarddirs.h \ 17 microkde/kstandarddirs.h \
18 microkde/ktempfile.h \ 18 microkde/ktempfile.h \
19 microkde/kunload.h \ 19 microkde/kunload.h \
20 microkde/kurlrequester.h \ 20 microkde/kurlrequester.h \
21 microkde/kfontdialog.h \ 21 microkde/kfontdialog.h \
22 microkde/krun.h \ 22 microkde/krun.h \
23 microkde/knumvalidator.h \ 23 microkde/knumvalidator.h \
24 microkde/kstaticdeleter.h \ 24 microkde/kstaticdeleter.h \
25 microkde/klistview.h \ 25 microkde/klistview.h \
26 microkde/kglobalsettings.h \ 26 microkde/kglobalsettings.h \
27 microkde/kcolorbtn.h \ 27 microkde/kcolorbtn.h \
28 \ 28 microkde/xmltree.h \
29 \ 29 microkde/qcolordialog.h \
30 qt3back/qregexp3.h \ 30 qt3back/qregexp3.h \
31 kde/ksharedptr.h \ 31 microkde/ksharedptr.h \
32 document/katebuffer.h document/katedialogs.h \ 32 document/katebuffer.h document/katedialogs.h \
33 document/katetextline.h \ 33 document/katetextline.h \
34 document/katecmd.h \ 34 document/katecmd.h \
35 document/katehighlight.h \ 35 document/katehighlight.h \
36 document/katecmds.h document/katedocument.h \ 36 document/katecmds.h document/katedocument.h \
37 document/katesyntaxdocument.h \ 37 document/katesyntaxdocument.h \
38 view/kateundohistory.h \ 38 view/kateundohistory.h \
39 view/kateview.h \ 39 view/kateview.h \
40 view/kateviewdialog.h \ 40 view/kateviewdialog.h \
41 interfaces/view.h \ 41 interfaces/view.h \
42 interfaces/document.h \ 42 interfaces/document.h \
43 ktexteditor/ktexteditor.h 43 ktexteditor/ktexteditor.h
44 44
45 SOURCES = microkde/kapplication.cpp \ 45 SOURCES = microkde/kapplication.cpp \
46 microkde/kdialogbase.cpp \ 46 microkde/kdialogbase.cpp \
47 kateconfig.cpp \ 47 kateconfig.cpp \
48 microkde/klocale.cpp \ 48 microkde/klocale.cpp \
49 microkde/kmessagebox.cpp \ 49 microkde/kmessagebox.cpp \
50 microkde/kprocess.cpp \ 50 microkde/kprocess.cpp \
51 microkde/kstandarddirs.cpp \ 51 microkde/kstandarddirs.cpp \
52 microkde/ktempfile.cpp \ 52 microkde/ktempfile.cpp \
53 microkde/kurlrequester.cpp \ 53 microkde/kurlrequester.cpp \
54 microkde/kcolordialog.cpp \ 54# microkde/kcolordialog.cpp \
55 microkde/kfontdialog.cpp \ 55 microkde/kfontdialog.cpp \
56 microkde/krun.cpp \ 56 microkde/krun.cpp \
57 microkde/knumvalidator.cpp \ 57 microkde/knumvalidator.cpp \
58 microkde/kglobal.cpp \ 58 microkde/kglobal.cpp \
59 microkde/kglobalsettings.cpp \ 59 microkde/kglobalsettings.cpp \
60 microkde/kcolorbtn.cpp \ 60 microkde/kcolorbtn.cpp \
61 \ 61 microkde/xmltree.cc \
62 \ 62 microkde/qcolordialog.cpp \
63 qt3back/qregexp3.cpp \ 63 qt3back/qregexp3.cpp \
64 ktexteditor/ktexteditor.cpp \ 64 ktexteditor/ktexteditor.cpp \
65 document/katebuffer.cpp document/katedialogs.cpp \ 65 document/katebuffer.cpp document/katedialogs.cpp \
66 document/katehighlight.cpp \ 66 document/katehighlight.cpp \
67 document/katecmd.cpp \ 67 document/katecmd.cpp \
68 document/katesyntaxdocument.cpp document/katecmds.cpp \ 68 document/katesyntaxdocument.cpp document/katecmds.cpp \
69 document/katedocument.cpp document/katetextline.cpp \ 69 document/katedocument.cpp document/katetextline.cpp \
70 view/kateundohistory.cpp \ 70 view/kateundohistory.cpp \
71 view/kateview.cpp \ 71 view/kateview.cpp \
72 view/kateviewdialog.cpp \ 72 view/kateviewdialog.cpp \
73 interfaces/interfaces.cpp 73 interfaces/interfaces.cpp
74 74
75 INTERFACES= 75 INTERFACES=
76 INCLUDEPATH+= $(OPIEDIR)/include \ 76 INCLUDEPATH+= $(OPIEDIR)/include \
77 $(OPIEDIR)/noncore/apps/tinykate/libkate \ 77 $(OPIEDIR)/noncore/apps/tinykate/libkate \
78 $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ 78 $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \
79 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ 79 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \
80 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ 80 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \
81 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ 81 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \
82 $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \ 82 $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \
83 $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back 83 $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back
84 DEPENDPATH+= $(OPIEDIR)/include 84 DEPENDPATH+= $(OPIEDIR)/include
85LIBS += -lqpe -lopie 85LIBS += -lqpe -lopie
86 TARGET = tinykate 86 TARGET = tinykate
87 87
88INCLUDEPATH += $(OPIEDIR)/include 88INCLUDEPATH += $(OPIEDIR)/include
89DESTDIR = $(OPIEDIR)/lib$(PROJMAK) 89DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
90 90
91include ( $(OPIEDIR)/include.pro ) 91include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/apps/tinykate/libkate/microkde/kcolordialog.cpp b/noncore/apps/tinykate/libkate/microkde/kcolordialog.cpp
deleted file mode 100644
index 3aee42a..0000000
--- a/noncore/apps/tinykate/libkate/microkde/kcolordialog.cpp
+++ b/dev/null
@@ -1,6 +0,0 @@
1#include "kcolordialog.h"
2
3int KColorDialog::getColor( const QColor & )
4{
5 return 0;
6}
diff --git a/noncore/apps/tinykate/libkate/microkde/qcolordialog.cpp b/noncore/apps/tinykate/libkate/microkde/qcolordialog.cpp
new file mode 100644
index 0000000..fe999b6
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/microkde/qcolordialog.cpp
@@ -0,0 +1,1631 @@
1/****************************************************************************
2** $Id$
3**
4** Implementation of KColorDialog class
5**
6** Created : 990222
7**
8** Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qcolordialog.h"
39
40#include <qpainter.h>
41#include <qlayout.h>
42#include <qlabel.h>
43#include <qpushbutton.h>
44#include <qlineedit.h>
45#include <qimage.h>
46#include <qpixmap.h>
47#include <qdrawutil.h>
48#include <qvalidator.h>
49#include <qdragobject.h>
50#include <qapplication.h>
51#include <qdragobject.h>
52
53//////////// QWellArray BEGIN
54
55#include <qobjectdict.h>
56
57//
58// W A R N I N G
59// -------------
60//
61// This file is not part of the Qt API. It exists for the convenience
62// of qwellarray.cpp and qcolordialog.cpp.
63// This header file may change from version to version without notice,
64// or even be removed.
65//
66//
67
68
69#include <qtableview.h>
70
71
72struct QWellArrayData;
73
74class QWellArray : public QTableView
75{
76 Q_OBJECT
77 Q_PROPERTY( int numCols READ numCols )
78 Q_PROPERTY( int numRows READ numRows )
79 Q_PROPERTY( int selectedColumn READ selectedColumn )
80 Q_PROPERTY( int selectedRow READ selectedRow )
81
82public:
83 QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE );
84
85 ~QWellArray() {}
86 QString cellContent( int row, int col ) const;
87 // ### Paul !!! virtual void setCellContent( int row, int col, const QString &);
88
89 // ##### Obsolete since not const
90 int numCols() { return nCols; }
91 int numRows() { return nRows; }
92
93 int numCols() const { return nCols; }
94 int numRows() const { return nRows; }
95
96 // ##### Obsolete since not const
97 int selectedColumn() { return selCol; }
98 int selectedRow() { return selRow; }
99
100 int selectedColumn() const { return selCol; }
101 int selectedRow() const { return selRow; }
102
103 virtual void setSelected( int row, int col );
104
105 void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); }
106
107 QSize sizeHint() const;
108
109 virtual void setDimension( int rows, int cols );
110 virtual void setCellBrush( int row, int col, const QBrush & );
111 QBrush cellBrush( int row, int col );
112
113signals:
114 void selected( int row, int col );
115
116protected:
117 virtual void setCurrent( int row, int col );
118
119 virtual void drawContents( QPainter *, int row, int col, const QRect& );
120 void drawContents( QPainter * );
121
122 void paintCell( QPainter*, int row, int col );
123 void mousePressEvent( QMouseEvent* );
124 void mouseReleaseEvent( QMouseEvent* );
125 void mouseMoveEvent( QMouseEvent* );
126 void keyPressEvent( QKeyEvent* );
127 void focusInEvent( QFocusEvent* );
128 void focusOutEvent( QFocusEvent* );
129
130private:
131 int curRow;
132 int curCol;
133 int selRow;
134 int selCol;
135 int nCols;
136 int nRows;
137 bool smallStyle;
138 QWellArrayData *d;
139
140 private:// Disabled copy constructor and operator=
141#if defined(Q_DISABLE_COPY)
142 QWellArray( const QWellArray & );
143 QWellArray& operator=( const QWellArray & );
144#endif
145};
146
147
148
149// non-interface ...
150
151
152
153struct QWellArrayData {
154 QBrush *brush;
155};
156
157// NOT REVISED
158/* WARNING, NOT
159 \class QWellArray qwellarray_p.h
160 \brief ....
161
162 ....
163
164 \ingroup advanced
165*/
166
167QWellArray::QWellArray( QWidget *parent, const char * name, bool popup )
168 : QTableView( parent, name,
169 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 )
170{
171 d = 0;
172 setFocusPolicy( StrongFocus );
173 setBackgroundMode( PaletteButton );
174 nCols = 7;
175 nRows = 7;
176 int w = 24; // cell width
177 int h = 21; // cell height
178 smallStyle = popup;
179
180 if ( popup ) {
181 w = h = 18;
182 if ( style() == WindowsStyle )
183 setFrameStyle( QFrame::WinPanel | QFrame::Raised );
184 else
185 setFrameStyle( QFrame::Panel | QFrame::Raised );
186 setMargin( 1 );
187 setLineWidth( 2 );
188 }
189 setNumCols( nCols );
190 setNumRows( nRows );
191 setCellWidth( w );
192 setCellHeight( h );
193 curCol = 0;
194 curRow = 0;
195 selCol = -1;
196 selRow = -1;
197
198 if ( smallStyle )
199 setMouseTracking( TRUE );
200 setOffset( 5 , 10 );
201
202 resize( sizeHint() );
203
204}
205
206
207QSize QWellArray::sizeHint() const
208{
209 constPolish();
210 int f = frameWidth() * 2;
211 int w = nCols * cellWidth() + f;
212 int h = nRows * cellHeight() + f;
213 return QSize( w, h );
214}
215
216
217void QWellArray::paintCell( QPainter* p, int row, int col )
218{
219 int w = cellWidth( col ); // width of cell in pixels
220 int h = cellHeight( row ); // height of cell in pixels
221 int b = 1;
222
223 if ( !smallStyle )
224 b = 3;
225
226 const QColorGroup & g = colorGroup();
227 p->setPen( QPen( black, 0, SolidLine ) );
228 if ( !smallStyle && row ==selRow && col == selCol &&
229 style() != MotifStyle ) {
230 int n = 2;
231 p->drawRect( n, n, w-2*n, h-2*n );
232 }
233
234
235 if ( style() == WindowsStyle ) {
236 qDrawWinPanel( p, b, b , w - 2*b, h - 2*b,
237 g, TRUE );
238 b += 2;
239 } else {
240 if ( smallStyle ) {
241 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
242 g, TRUE, 2 );
243 b += 2;
244 } else {
245 int t = ( row == selRow && col == selCol ) ? 2 : 0;
246 b -= t;
247 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
248 g, TRUE, 2 );
249 b += 2 + t;
250 }
251 }
252
253
254 if ( (row == curRow) && (col == curCol) ) {
255 if ( smallStyle ) {
256 p->setPen ( white );
257 p->drawRect( 1, 1, w-2, h-2 );
258 p->setPen ( black );
259 p->drawRect( 0, 0, w, h );
260 p->drawRect( 2, 2, w-4, h-4 );
261 b = 3;
262 } else if ( hasFocus() ) {
263 style().drawFocusRect(p, QRect(0,0,w,h), g );
264 }
265 }
266 drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) );
267}
268
269/*!
270 Pass-through to QTableView::drawContents() to avoid hiding.
271*/
272void QWellArray::drawContents( QPainter *p )
273{
274 QTableView::drawContents(p);
275}
276
277/*!
278 Reimplement this function to change the contents of the well array.
279 */
280void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r )
281{
282
283 if ( d ) {
284 p->fillRect( r, d->brush[row*nCols+col] );
285 } else {
286 p->fillRect( r, white );
287 p->setPen( black );
288 p->drawLine( r.topLeft(), r.bottomRight() );
289 p->drawLine( r.topRight(), r.bottomLeft() );
290 }
291}
292
293
294/*\reimp
295*/
296void QWellArray::mousePressEvent( QMouseEvent* e )
297{
298 // The current cell marker is set to the cell the mouse is pressed
299 // in.
300 QPoint pos = e->pos();
301 setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
302}
303
304/*\reimp
305*/
306void QWellArray::mouseReleaseEvent( QMouseEvent* )
307{
308 // The current cell marker is set to the cell the mouse is clicked
309 // in.
310 setSelected( curRow, curCol );
311}
312
313
314/*\reimp
315*/
316void QWellArray::mouseMoveEvent( QMouseEvent* e )
317{
318 // The current cell marker is set to the cell the mouse is
319 // clicked in.
320 if ( smallStyle ) {
321 QPoint pos = e->pos();
322 setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
323 }
324}
325
326/*
327 Sets the cell currently having the focus. This is not necessarily
328 the same as the currently selected cell.
329*/
330
331void QWellArray::setCurrent( int row, int col )
332{
333
334 if ( (curRow == row) && (curCol == col) )
335 return;
336
337 if ( row < 0 || col < 0 )
338 row = col = -1;
339
340 int oldRow = curRow;
341 int oldCol = curCol;
342
343 curRow = row;
344 curCol = col;
345
346 updateCell( oldRow, oldCol );
347 updateCell( curRow, curCol );
348}
349
350
351/*!
352 Sets the currently selected cell to \a row, \a col. If \a row or \a
353 col are less than zero, the current cell is unselected.
354
355 Does not set the position of the focus indicator.
356*/
357
358void QWellArray::setSelected( int row, int col )
359{
360 if ( (selRow == row) && (selCol == col) )
361 return;
362
363 int oldRow = selRow;
364 int oldCol = selCol;
365
366 if ( row < 0 || col < 0 )
367 row = col = -1;
368
369 selCol = col;
370 selRow = row;
371
372 updateCell( oldRow, oldCol );
373 updateCell( selRow, selCol );
374 if ( row >= 0 )
375 emit selected( row, col );
376
377 if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") )
378 parentWidget()->close();
379
380}
381
382
383
384/*!\reimp
385*/
386void QWellArray::focusInEvent( QFocusEvent* )
387{
388 updateCell( curRow, curCol );
389}
390
391
392/*!
393 Sets the size of the well array to be \c rows cells by \c cols.
394 Resets any brush info set by setCellBrush().
395
396 Must be called by reimplementors.
397 */
398void QWellArray::setDimension( int rows, int cols )
399{
400 nRows = rows;
401 nCols = cols;
402 if ( d ) {
403 if ( d->brush )
404 delete[] d->brush;
405 delete d;
406 d = 0;
407 }
408 setNumCols( nCols );
409 setNumRows( nRows );
410}
411
412void QWellArray::setCellBrush( int row, int col, const QBrush &b )
413{
414 if ( !d ) {
415 d = new QWellArrayData;
416 d->brush = new QBrush[nRows*nCols];
417 }
418 if ( row >= 0 && row < nRows && col >= 0 && col < nCols )
419 d->brush[row*nCols+col] = b;
420#ifdef CHECK_RANGE
421 else
422 qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col );
423#endif
424}
425
426
427
428/*!
429 Returns the brush set for the cell at \a row, \a col. If no brush is set,
430 \c NoBrush is returned.
431*/
432
433QBrush QWellArray::cellBrush( int row, int col )
434{
435 if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols )
436 return d->brush[row*nCols+col];
437 return NoBrush;
438}
439
440
441
442/*!\reimp
443*/
444
445void QWellArray::focusOutEvent( QFocusEvent* )
446{
447 updateCell( curRow, curCol );
448}
449
450/*\reimp
451*/
452void QWellArray::keyPressEvent( QKeyEvent* e )
453{
454 switch( e->key() ) { // Look at the key code
455 case Key_Left: // If 'left arrow'-key,
456 if( curCol > 0 ) { // and cr't not in leftmost col
457 setCurrent( curRow, curCol - 1);// set cr't to next left column
458 int edge = leftCell(); // find left edge
459 if ( curCol < edge ) // if we have moved off edge,
460 setLeftCell( edge - 1 );// scroll view to rectify
461 }
462 break;
463 case Key_Right: // Correspondingly...
464 if( curCol < numCols()-1 ) {
465 setCurrent( curRow, curCol + 1);
466 int edge = lastColVisible();
467 if ( curCol >= edge )
468 setLeftCell( leftCell() + 1 );
469 }
470 break;
471 case Key_Up:
472 if( curRow > 0 ) {
473 setCurrent( curRow - 1, curCol);
474 int edge = topCell();
475 if ( curRow < edge )
476 setTopCell( edge - 1 );
477 } else if ( smallStyle )
478 focusNextPrevChild( FALSE );
479 break;
480 case Key_Down:
481 if( curRow < numRows()-1 ) {
482 setCurrent( curRow + 1, curCol);
483 int edge = lastRowVisible();
484 if ( curRow >= edge )
485 setTopCell( topCell() + 1 );
486 } else if ( smallStyle )
487 focusNextPrevChild( TRUE );
488 break;
489 case Key_Space:
490 case Key_Return:
491 case Key_Enter:
492 setSelected( curRow, curCol );
493 break;
494 default: // If not an interesting key,
495 e->ignore(); // we don't accept the event
496 return;
497 }
498
499}
500
501//////////// QWellArray END
502
503static bool initrgb = FALSE;
504static QRgb stdrgb[6*8];
505static QRgb cusrgb[2*8];
506
507
508static void initRGB()
509{
510 if ( initrgb )
511 return;
512 initrgb = TRUE;
513 int i = 0;
514 for ( int g = 0; g < 4; g++ )
515 for ( int r = 0; r < 4; r++ )
516 for ( int b = 0; b < 3; b++ )
517 stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 );
518
519 for ( i = 0; i < 2*8; i++ )
520 cusrgb[i] = qRgb(0xff,0xff,0xff);
521}
522
523/*!
524 Returns the number of custom colors supported by
525 KColorDialog. All color dialogs share the same custom colors.
526*/
527int KColorDialog::customCount()
528{
529 return 2*8;
530}
531
532/*!
533 Returns custom color number \a i as a QRgb.
534 */
535QRgb KColorDialog::customColor( int i )
536{
537 initRGB();
538 if ( i < 0 || i >= customCount() ) {
539#ifdef CHECK_RANGE
540 qWarning( "KColorDialog::customColor() index %d out of range", i );
541 #endif
542 i = 0;
543 }
544 return cusrgb[i];
545}
546
547/*!
548 Sets custom color number \a i to the QRgb value \a c.
549*/
550void KColorDialog::setCustomColor( int i, QRgb c )
551{
552 initRGB();
553 if ( i < 0 || i >= customCount() ) {
554#ifdef CHECK_RANGE
555 qWarning( "KColorDialog::customColor() index %d out of range", i );
556 #endif
557 return;
558 }
559 cusrgb[i] = c;
560}
561
562static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
563{
564 QColor c;
565 c.setRgb( rgb );
566 c.getHsv(h,s,v);
567}
568
569class QColorWell : public QWellArray
570{
571public:
572 QColorWell( QWidget *parent, int r, int c, QRgb *vals )
573 :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 )
574 { setDimension(r,c); setWFlags( WResizeNoErase ); }
575 QSizePolicy sizePolicy() const;
576
577protected:
578 void drawContents( QPainter *, int row, int col, const QRect& );
579 void drawContents( QPainter *p ) { QWellArray::drawContents(p); }
580 void mousePressEvent( QMouseEvent *e );
581 void mouseMoveEvent( QMouseEvent *e );
582 void mouseReleaseEvent( QMouseEvent *e );
583#ifndef QT_NO_DRAGANDDROP
584 void dragEnterEvent( QDragEnterEvent *e );
585 void dragLeaveEvent( QDragLeaveEvent *e );
586 void dragMoveEvent( QDragMoveEvent *e );
587 void dropEvent( QDropEvent *e );
588#endif
589
590private:
591 QRgb *values;
592 bool mousePressed;
593 QPoint pressPos;
594 QPoint oldCurrent;
595
596};
597
598QSizePolicy QColorWell::sizePolicy() const
599{
600 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
601}
602
603void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r )
604{
605 int i = row + col*numRows();
606 p->fillRect( r, QColor( values[i] ) );
607}
608
609void QColorWell::mousePressEvent( QMouseEvent *e )
610{
611 oldCurrent = QPoint( selectedRow(), selectedColumn() );
612 QWellArray::mousePressEvent( e );
613 mousePressed = TRUE;
614 pressPos = e->pos();
615}
616
617void QColorWell::mouseMoveEvent( QMouseEvent *e )
618{
619 QWellArray::mouseMoveEvent( e );
620#ifndef QT_NO_DRAGANDDROP
621 if ( !mousePressed )
622 return;
623 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
624 setCurrent( oldCurrent.x(), oldCurrent.y() );
625 int i = findRow( e->y() ) + findCol( e->x() ) * numRows();
626 QColor col( values[ i ] );
627 QColorDrag *drg = new QColorDrag( col, this );
628 QPixmap pix( cellWidth(), cellHeight() );
629 pix.fill( col );
630 QPainter p( &pix );
631 p.drawRect( 0, 0, pix.width(), pix.height() );
632 p.end();
633 drg->setPixmap( pix );
634 mousePressed = FALSE;
635 drg->dragCopy();
636 }
637#endif
638}
639
640#ifndef QT_NO_DRAGANDDROP
641void QColorWell::dragEnterEvent( QDragEnterEvent *e )
642{
643 setFocus();
644 if ( QColorDrag::canDecode( e ) )
645 e->accept();
646 else
647 e->ignore();
648}
649
650void QColorWell::dragLeaveEvent( QDragLeaveEvent * )
651{
652 if ( hasFocus() )
653 parentWidget()->setFocus();
654}
655
656void QColorWell::dragMoveEvent( QDragMoveEvent *e )
657{
658 if ( QColorDrag::canDecode( e ) ) {
659 setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) );
660 e->accept();
661 } else
662 e->ignore();
663}
664
665void QColorWell::dropEvent( QDropEvent *e )
666{
667 if ( QColorDrag::canDecode( e ) ) {
668 int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows();
669 QColor col;
670 QColorDrag::decode( e, col );
671 values[ i ] = col.rgb();
672 repaint( FALSE );
673 e->accept();
674 } else {
675 e->ignore();
676 }
677}
678
679#endif // QT_NO_DRAGANDDROP
680
681void QColorWell::mouseReleaseEvent( QMouseEvent *e )
682{
683 if ( !mousePressed )
684 return;
685 QWellArray::mouseReleaseEvent( e );
686 mousePressed = FALSE;
687}
688
689class QColorPicker : public QFrame
690{
691 Q_OBJECT
692public:
693 QColorPicker(QWidget* parent=0, const char* name=0);
694 ~QColorPicker();
695
696public slots:
697 void setCol( int h, int s );
698
699signals:
700 void newCol( int h, int s );
701
702protected:
703 QSize sizeHint() const;
704 QSizePolicy sizePolicy() const;
705 void drawContents(QPainter* p);
706 void mouseMoveEvent( QMouseEvent * );
707 void mousePressEvent( QMouseEvent * );
708
709private:
710 int hue;
711 int sat;
712
713 QPoint colPt();
714 int huePt( const QPoint &pt );
715 int satPt( const QPoint &pt );
716 void setCol( const QPoint &pt );
717
718 QPixmap *pix;
719};
720
721static int pWidth = 200;
722static int pHeight = 200;
723
724class QColorLuminancePicker : public QWidget
725{
726 Q_OBJECT
727public:
728 QColorLuminancePicker(QWidget* parent=0, const char* name=0);
729 ~QColorLuminancePicker();
730
731public slots:
732 void setCol( int h, int s, int v );
733 void setCol( int h, int s );
734
735signals:
736 void newHsv( int h, int s, int v );
737
738protected:
739// QSize sizeHint() const;
740// QSizePolicy sizePolicy() const;
741 void paintEvent( QPaintEvent*);
742 void mouseMoveEvent( QMouseEvent * );
743 void mousePressEvent( QMouseEvent * );
744
745private:
746 enum { foff = 3, coff = 4 }; //frame and contents offset
747 int val;
748 int hue;
749 int sat;
750
751 int y2val( int y );
752 int val2y( int val );
753 void setVal( int v );
754
755 QPixmap *pix;
756};
757
758
759int QColorLuminancePicker::y2val( int y )
760{
761 int d = height() - 2*coff - 1;
762 return 255 - (y - coff)*255/d;
763}
764
765int QColorLuminancePicker::val2y( int v )
766{
767 int d = height() - 2*coff - 1;
768 return coff + (255-v)*d/255;
769}
770
771QColorLuminancePicker::QColorLuminancePicker(QWidget* parent,
772 const char* name)
773 :QWidget( parent, name )
774{
775 hue = 100; val = 100; sat = 100;
776 pix = 0;
777 // setBackgroundMode( NoBackground );
778}
779
780QColorLuminancePicker::~QColorLuminancePicker()
781{
782 delete pix;
783}
784
785void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m )
786{
787 setVal( y2val(m->y()) );
788}
789void QColorLuminancePicker::mousePressEvent( QMouseEvent *m )
790{
791 setVal( y2val(m->y()) );
792}
793
794void QColorLuminancePicker::setVal( int v )
795{
796 if ( val == v )
797 return;
798 val = QMAX( 0, QMIN(v,255));
799 delete pix; pix=0;
800 repaint( FALSE ); //###
801 emit newHsv( hue, sat, val );
802}
803
804//receives from a hue,sat chooser and relays.
805void QColorLuminancePicker::setCol( int h, int s )
806{
807 setCol( h, s, val );
808 emit newHsv( h, s, val );
809}
810
811void QColorLuminancePicker::paintEvent( QPaintEvent * )
812{
813 int w = width() - 5;
814
815 QRect r( 0, foff, w, height() - 2*foff );
816 int wi = r.width() - 2;
817 int hi = r.height() - 2;
818 if ( !pix || pix->height() != hi || pix->width() != wi ) {
819 delete pix;
820 QImage img( wi, hi, 32 );
821 int y;
822 for ( y = 0; y < hi; y++ ) {
823 QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
824 QRgb r = c.rgb();
825 int x;
826 for ( x = 0; x < wi; x++ )
827 img.setPixel( x, y, r );
828 }
829 pix = new QPixmap;
830 pix->convertFromImage(img);
831 }
832 QPainter p(this);
833 p.drawPixmap( 1, coff, *pix );
834 QColorGroup g = colorGroup();
835 qDrawShadePanel( &p, r, g, TRUE );
836 p.setPen( g.foreground() );
837 p.setBrush( g.foreground() );
838 QPointArray a;
839 int y = val2y(val);
840 a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 );
841 erase( w, 0, 5, height() );
842 p.drawPolygon( a );
843}
844
845void QColorLuminancePicker::setCol( int h, int s , int v )
846{
847 val = v;
848 hue = h;
849 sat = s;
850 delete pix; pix=0;
851 repaint( FALSE );//####
852}
853
854QPoint QColorPicker::colPt()
855{ return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); }
856int QColorPicker::huePt( const QPoint &pt )
857{ return 360 - pt.x()*360/(pWidth-1); }
858int QColorPicker::satPt( const QPoint &pt )
859{ return 255 - pt.y()*255/(pHeight-1) ; }
860void QColorPicker::setCol( const QPoint &pt )
861{ setCol( huePt(pt), satPt(pt) ); }
862
863QColorPicker::QColorPicker(QWidget* parent, const char* name )
864 : QFrame( parent, name )
865{
866 hue = 0; sat = 0;
867 setCol( 150, 255 );
868
869 QImage img( pWidth, pHeight, 32 );
870 int x,y;
871 for ( y = 0; y < pHeight; y++ )
872 for ( x = 0; x < pWidth; x++ ) {
873 QPoint p( x, y );
874 img.setPixel( x, y, QColor(huePt(p), satPt(p),
875 200, QColor::Hsv).rgb() );
876 }
877 pix = new QPixmap;
878 pix->convertFromImage(img);
879 setBackgroundMode( NoBackground );
880}
881
882QColorPicker::~QColorPicker()
883{
884 delete pix;
885}
886
887QSize QColorPicker::sizeHint() const
888{
889 return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() );
890}
891
892QSizePolicy QColorPicker::sizePolicy() const
893{
894 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
895}
896
897void QColorPicker::setCol( int h, int s )
898{
899 int nhue = QMIN( QMAX(0,h), 360 );
900 int nsat = QMIN( QMAX(0,s), 255);
901 if ( nhue == hue && nsat == sat )
902 return;
903 QRect r( colPt(), QSize(20,20) );
904 hue = nhue; sat = nsat;
905 r = r.unite( QRect( colPt(), QSize(20,20) ) );
906 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 );
907 // update( r );
908 repaint( r, FALSE );
909}
910
911void QColorPicker::mouseMoveEvent( QMouseEvent *m )
912{
913 QPoint p = m->pos() - contentsRect().topLeft();
914 setCol( p );
915 emit newCol( hue, sat );
916}
917
918void QColorPicker::mousePressEvent( QMouseEvent *m )
919{
920 QPoint p = m->pos() - contentsRect().topLeft();
921 setCol( p );
922 emit newCol( hue, sat );
923}
924
925void QColorPicker::drawContents(QPainter* p)
926{
927 QRect r = contentsRect();
928
929 p->drawPixmap( r.topLeft(), *pix );
930 QPoint pt = colPt() + r.topLeft();
931 p->setPen( QPen(black) );
932
933 p->fillRect( pt.x()-9, pt.y(), 20, 2, black );
934 p->fillRect( pt.x(), pt.y()-9, 2, 20, black );
935
936}
937
938class QColorShowLabel;
939
940
941
942class QColIntValidator: public QIntValidator
943{
944public:
945 QColIntValidator( int bottom, int top,
946 QWidget * parent, const char *name = 0 )
947 :QIntValidator( bottom, top, parent, name ) {}
948
949 QValidator::State validate( QString &, int & ) const;
950};
951
952QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
953{
954 State state = QIntValidator::validate(s,pos);
955 if ( state == Valid ) {
956 long int val = s.toLong();
957 // This is not a general solution, assumes that top() > 0 and
958 // bottom >= 0
959 if ( val < 0 ) {
960 s = "0";
961 pos = 1;
962 } else if ( val > top() ) {
963 s.setNum( top() );
964 pos = s.length();
965 }
966 }
967 return state;
968}
969
970
971
972class QColNumLineEdit : public QLineEdit
973{
974public:
975 QColNumLineEdit( QWidget *parent, const char* name = 0 )
976 : QLineEdit( parent, name ) { setMaxLength( 3 );}
977 QSize sizeHint() const {
978 return QSize( 30, //#####
979 QLineEdit::sizeHint().height() ); }
980 void setNum( int i ) {
981 QString s;
982 s.setNum(i);
983 bool block = signalsBlocked();
984 blockSignals(TRUE);
985 setText( s );
986 blockSignals(block);
987 }
988 int val() const { return text().toInt(); }
989};
990
991
992class QColorShower : public QWidget
993{
994 Q_OBJECT
995public:
996 QColorShower( QWidget *parent, const char *name = 0 );
997
998 //things that don't emit signals
999 void setHsv( int h, int s, int v );
1000
1001 int currentAlpha() const { return alphaEd->val(); }
1002 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
1003 void showAlpha( bool b );
1004
1005
1006 QRgb currentColor() const { return curCol; }
1007
1008public slots:
1009 void setRgb( QRgb rgb );
1010
1011signals:
1012 void newCol( QRgb rgb );
1013private slots:
1014 void rgbEd();
1015 void hsvEd();
1016private:
1017 void showCurrentColor();
1018 int hue, sat, val;
1019 QRgb curCol;
1020 QColNumLineEdit *hEd;
1021 QColNumLineEdit *sEd;
1022 QColNumLineEdit *vEd;
1023 QColNumLineEdit *rEd;
1024 QColNumLineEdit *gEd;
1025 QColNumLineEdit *bEd;
1026 QColNumLineEdit *alphaEd;
1027 QLabel *alphaLab;
1028 QColorShowLabel *lab;
1029 bool rgbOriginal;
1030};
1031
1032class QColorShowLabel : public QFrame
1033{
1034 Q_OBJECT
1035
1036public:
1037 QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
1038 setFrameStyle( QFrame::Panel|QFrame::Sunken );
1039 setBackgroundMode( PaletteBackground );
1040 setAcceptDrops( TRUE );
1041 mousePressed = FALSE;
1042 }
1043 void setColor( QColor c ) { col = c; }
1044
1045signals:
1046 void colorDropped( QRgb );
1047
1048protected:
1049 void drawContents( QPainter *p );
1050 void mousePressEvent( QMouseEvent *e );
1051 void mouseMoveEvent( QMouseEvent *e );
1052 void mouseReleaseEvent( QMouseEvent *e );
1053#ifndef QT_NO_DRAGANDDROP
1054 void dragEnterEvent( QDragEnterEvent *e );
1055 void dragLeaveEvent( QDragLeaveEvent *e );
1056 void dropEvent( QDropEvent *e );
1057#endif
1058
1059private:
1060 QColor col;
1061 bool mousePressed;
1062 QPoint pressPos;
1063
1064};
1065
1066void QColorShowLabel::drawContents( QPainter *p )
1067{
1068 p->fillRect( contentsRect(), col );
1069}
1070
1071void QColorShower::showAlpha( bool b )
1072{
1073 if ( b ) {
1074 alphaLab->show();
1075 alphaEd->show();
1076 } else {
1077 alphaLab->hide();
1078 alphaEd->hide();
1079 }
1080}
1081
1082void QColorShowLabel::mousePressEvent( QMouseEvent *e )
1083{
1084 mousePressed = TRUE;
1085 pressPos = e->pos();
1086}
1087
1088void QColorShowLabel::mouseMoveEvent( QMouseEvent *e )
1089{
1090#ifndef QT_NO_DRAGANDDROP
1091 if ( !mousePressed )
1092 return;
1093 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
1094 QColorDrag *drg = new QColorDrag( col, this );
1095 QPixmap pix( 30, 20 );
1096 pix.fill( col );
1097 QPainter p( &pix );
1098 p.drawRect( 0, 0, pix.width(), pix.height() );
1099 p.end();
1100 drg->setPixmap( pix );
1101 mousePressed = FALSE;
1102 drg->dragCopy();
1103 }
1104#endif
1105}
1106
1107#ifndef QT_NO_DRAGANDDROP
1108void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e )
1109{
1110 if ( QColorDrag::canDecode( e ) )
1111 e->accept();
1112 else
1113 e->ignore();
1114}
1115
1116void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * )
1117{
1118}
1119
1120void QColorShowLabel::dropEvent( QDropEvent *e )
1121{
1122 if ( QColorDrag::canDecode( e ) ) {
1123 QColorDrag::decode( e, col );
1124 repaint( FALSE );
1125 emit colorDropped( col.rgb() );
1126 e->accept();
1127 } else {
1128 e->ignore();
1129 }
1130}
1131#endif // QT_NO_DRAGANDDROP
1132
1133void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
1134{
1135 if ( !mousePressed )
1136 return;
1137 mousePressed = FALSE;
1138}
1139
1140QColorShower::QColorShower( QWidget *parent, const char *name )
1141 :QWidget( parent, name)
1142{
1143 curCol = qRgb( -1, -1, -1 );
1144 QColIntValidator *val256 = new QColIntValidator( 0, 255, this );
1145 QColIntValidator *val360 = new QColIntValidator( 0, 360, this );
1146
1147 QGridLayout *gl = new QGridLayout( this, 1, 1, 6 );
1148 lab = new QColorShowLabel( this );
1149 lab->setMinimumWidth( 60 ); //###
1150 gl->addMultiCellWidget(lab, 0,-1,0,0);
1151 connect( lab, SIGNAL( colorDropped( QRgb ) ),
1152 this, SIGNAL( newCol( QRgb ) ) );
1153 connect( lab, SIGNAL( colorDropped( QRgb ) ),
1154 this, SLOT( setRgb( QRgb ) ) );
1155
1156 hEd = new QColNumLineEdit( this );
1157 hEd->setValidator( val360 );
1158 QLabel *l = new QLabel( hEd, KColorDialog::tr("Hu&e:"), this );
1159 l->setAlignment( AlignRight|AlignVCenter );
1160 gl->addWidget( l, 0, 1 );
1161 gl->addWidget( hEd, 0, 2 );
1162
1163 sEd = new QColNumLineEdit( this );
1164 sEd->setValidator( val256 );
1165 l = new QLabel( sEd, KColorDialog::tr("&Sat:"), this );
1166 l->setAlignment( AlignRight|AlignVCenter );
1167 gl->addWidget( l, 1, 1 );
1168 gl->addWidget( sEd, 1, 2 );
1169
1170 vEd = new QColNumLineEdit( this );
1171 vEd->setValidator( val256 );
1172 l = new QLabel( vEd, KColorDialog::tr("&Val:"), this );
1173 l->setAlignment( AlignRight|AlignVCenter );
1174 gl->addWidget( l, 2, 1 );
1175 gl->addWidget( vEd, 2, 2 );
1176
1177 rEd = new QColNumLineEdit( this );
1178 rEd->setValidator( val256 );
1179 l = new QLabel( rEd, KColorDialog::tr("&Red:"), this );
1180 l->setAlignment( AlignRight|AlignVCenter );
1181 gl->addWidget( l, 0, 3 );
1182 gl->addWidget( rEd, 0, 4 );
1183
1184 gEd = new QColNumLineEdit( this );
1185 gEd->setValidator( val256 );
1186 l = new QLabel( gEd, KColorDialog::tr("&Green:"), this );
1187 l->setAlignment( AlignRight|AlignVCenter );
1188 gl->addWidget( l, 1, 3 );
1189 gl->addWidget( gEd, 1, 4 );
1190
1191 bEd = new QColNumLineEdit( this );
1192 bEd->setValidator( val256 );
1193 l = new QLabel( bEd, KColorDialog::tr("Bl&ue:"), this );
1194 l->setAlignment( AlignRight|AlignVCenter );
1195 gl->addWidget( l, 2, 3 );
1196 gl->addWidget( bEd, 2, 4 );
1197
1198 alphaEd = new QColNumLineEdit( this );
1199 alphaEd->setValidator( val256 );
1200 alphaLab = new QLabel( alphaEd, KColorDialog::tr("A&lpha channel:"), this );
1201 alphaLab->setAlignment( AlignRight|AlignVCenter );
1202 gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 );
1203 gl->addWidget( alphaEd, 3, 4 );
1204 alphaEd->hide();
1205 alphaLab->hide();
1206
1207 connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1208 connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1209 connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1210
1211 connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1212 connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1213 connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1214}
1215
1216void QColorShower::showCurrentColor()
1217{
1218 lab->setColor( currentColor() );
1219 lab->repaint(FALSE); //###
1220}
1221
1222void QColorShower::rgbEd()
1223{
1224 rgbOriginal = TRUE;
1225 curCol = qRgb( rEd->val(), gEd->val(), bEd->val() );
1226 rgb2hsv(currentColor(), hue, sat, val );
1227
1228 hEd->setNum( hue );
1229 sEd->setNum( sat );
1230 vEd->setNum( val );
1231
1232 showCurrentColor();
1233 emit newCol( currentColor() );
1234}
1235
1236void QColorShower::hsvEd()
1237{
1238 rgbOriginal = FALSE;
1239 hue = hEd->val();
1240 sat = sEd->val();
1241 val = vEd->val();
1242
1243 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
1244
1245 rEd->setNum( qRed(currentColor()) );
1246 gEd->setNum( qGreen(currentColor()) );
1247 bEd->setNum( qBlue(currentColor()) );
1248
1249 showCurrentColor();
1250 emit newCol( currentColor() );
1251}
1252
1253void QColorShower::setRgb( QRgb rgb )
1254{
1255 rgbOriginal = TRUE;
1256 curCol = rgb;
1257
1258 rgb2hsv( currentColor(), hue, sat, val );
1259
1260 hEd->setNum( hue );
1261 sEd->setNum( sat );
1262 vEd->setNum( val );
1263
1264 rEd->setNum( qRed(currentColor()) );
1265 gEd->setNum( qGreen(currentColor()) );
1266 bEd->setNum( qBlue(currentColor()) );
1267
1268 showCurrentColor();
1269}
1270
1271void QColorShower::setHsv( int h, int s, int v )
1272{
1273 rgbOriginal = FALSE;
1274 hue = h; val = v; sat = s; //Range check###
1275 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
1276
1277 hEd->setNum( hue );
1278 sEd->setNum( sat );
1279 vEd->setNum( val );
1280
1281 rEd->setNum( qRed(currentColor()) );
1282 gEd->setNum( qGreen(currentColor()) );
1283 bEd->setNum( qBlue(currentColor()) );
1284
1285
1286 showCurrentColor();
1287}
1288
1289class KColorDialogPrivate : public QObject
1290{
1291Q_OBJECT
1292public:
1293 KColorDialogPrivate( KColorDialog *p );
1294 QRgb currentColor() const { return cs->currentColor(); }
1295 void setCurrentColor( QRgb rgb );
1296
1297 int currentAlpha() const { return cs->currentAlpha(); }
1298 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
1299 void showAlpha( bool b ) { cs->showAlpha( b ); }
1300
1301private slots:
1302 void addCustom();
1303
1304 void newHsv( int h, int s, int v );
1305 void newColorTypedIn( QRgb rgb );
1306 void newCustom( int, int );
1307 void newStandard( int, int );
1308private:
1309 QColorPicker *cp;
1310 QColorLuminancePicker *lp;
1311 QWellArray *custom;
1312 QWellArray *standard;
1313 QColorShower *cs;
1314 int nextCust;
1315 bool compact;
1316};
1317
1318//sets all widgets to display h,s,v
1319void KColorDialogPrivate::newHsv( int h, int s, int v )
1320{
1321 cs->setHsv( h, s, v );
1322 cp->setCol( h, s );
1323 lp->setCol( h, s, v );
1324}
1325
1326//sets all widgets to display rgb
1327void KColorDialogPrivate::setCurrentColor( QRgb rgb )
1328{
1329 cs->setRgb( rgb );
1330 newColorTypedIn( rgb );
1331}
1332
1333//sets all widgets exept cs to display rgb
1334void KColorDialogPrivate::newColorTypedIn( QRgb rgb )
1335{
1336 int h, s, v;
1337 rgb2hsv(rgb, h, s, v );
1338 cp->setCol( h, s );
1339 lp->setCol( h, s, v);
1340}
1341
1342void KColorDialogPrivate::newCustom( int r, int c )
1343{
1344 int i = r+2*c;
1345 setCurrentColor( cusrgb[i] );
1346 nextCust = i;
1347 standard->setSelected(-1,-1);
1348}
1349
1350void KColorDialogPrivate::newStandard( int r, int c )
1351{
1352 setCurrentColor( stdrgb[r+c*6] );
1353 custom->setSelected(-1,-1);
1354}
1355
1356KColorDialogPrivate::KColorDialogPrivate( KColorDialog *dialog ) :
1357 QObject(dialog)
1358{
1359 compact = FALSE;
1360 // small displays (e.g. PDAs cannot fit the full color dialog,
1361 // so just use the color picker.
1362 if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 )
1363 compact = TRUE;
1364
1365 nextCust = 0;
1366 const int lumSpace = 3;
1367 int border = 12;
1368 if ( compact )
1369 border = 6;
1370 QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 );
1371 QVBoxLayout *leftLay = 0;
1372
1373 if ( !compact )
1374 leftLay = new QVBoxLayout( topLay );
1375
1376 initRGB();
1377
1378 if ( !compact ) {
1379 standard = new QColorWell( dialog, 6, 8, stdrgb );
1380 standard->setCellSize( 28, 24 );
1381 QLabel * lab = new QLabel( standard,
1382 KColorDialog::tr( "&Basic colors"), dialog );
1383 connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int)));
1384 leftLay->addWidget( lab );
1385 leftLay->addWidget( standard );
1386
1387
1388 leftLay->addStretch();
1389
1390 custom = new QColorWell( dialog, 2, 8, cusrgb );
1391 custom->setCellSize( 28, 24 );
1392 custom->setAcceptDrops( TRUE );
1393
1394 connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int)));
1395 lab = new QLabel( custom, KColorDialog::tr( "&Custom colors") , dialog );
1396 leftLay->addWidget( lab );
1397 leftLay->addWidget( custom );
1398
1399 QPushButton *custbut =
1400 new QPushButton( KColorDialog::tr("&Define Custom Colors >>"),
1401 dialog );
1402 custbut->setEnabled( FALSE );
1403 leftLay->addWidget( custbut );
1404 } else {
1405 // better color picker size for small displays
1406 pWidth = 150;
1407 pHeight = 100;
1408 }
1409
1410 QVBoxLayout *rightLay = new QVBoxLayout( topLay );
1411
1412 QHBoxLayout *pickLay = new QHBoxLayout( rightLay );
1413
1414
1415 QVBoxLayout *cLay = new QVBoxLayout( pickLay );
1416 cp = new QColorPicker( dialog );
1417 cp->setFrameStyle( QFrame::Panel + QFrame::Sunken );
1418 cLay->addSpacing( lumSpace );
1419 cLay->addWidget( cp );
1420 cLay->addSpacing( lumSpace );
1421
1422 lp = new QColorLuminancePicker( dialog );
1423 lp->setFixedWidth( 20 ); //###
1424 pickLay->addWidget( lp );
1425
1426 connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) );
1427 connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) );
1428
1429 rightLay->addStretch();
1430
1431 cs = new QColorShower( dialog );
1432 connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb)));
1433 rightLay->addWidget( cs );
1434
1435 QHBoxLayout *buttons;
1436 if ( compact )
1437 buttons = new QHBoxLayout( rightLay );
1438 else
1439 buttons = new QHBoxLayout( leftLay );
1440
1441 QPushButton *ok, *cancel;
1442 ok = new QPushButton( KColorDialog::tr("OK"), dialog );
1443 connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) );
1444 ok->setDefault(TRUE);
1445 cancel = new QPushButton( KColorDialog::tr("Cancel"), dialog );
1446 connect( cancel, SIGNAL(clicked()), dialog, SLOT(reject()) );
1447 buttons->addWidget( ok );
1448 buttons->addWidget( cancel );
1449 buttons->addStretch();
1450
1451 if ( !compact ) {
1452 QPushButton *addCusBt = new QPushButton(
1453 KColorDialog::tr("&Add To Custom Colors"),
1454 dialog );
1455 rightLay->addWidget( addCusBt );
1456 connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) );
1457 }
1458}
1459
1460void KColorDialogPrivate::addCustom()
1461{
1462 cusrgb[nextCust] = cs->currentColor();
1463 custom->repaint( FALSE ); //###
1464 nextCust = (nextCust+1) % 16;
1465}
1466
1467
1468// BEING REVISED: jo
1469/*!
1470 \class KColorDialog qcolordialog.h
1471 \brief The KColorDialog class provides a dialog widget for specifying colors.
1472 \ingroup dialogs
1473
1474 The color dialog's function is to allow users to choose colors -
1475 for instance, you might use this in a drawing program to allow the
1476 user to set the brush color.
1477
1478 This version of Qt only provides modal color dialogs. The static
1479 getColor() function shows the dialog and allows the user to specify a color,
1480 while getRgba() does the same but allows the user to specify a color with an
1481 alpha channel (transparency) value.
1482
1483 The user can store customCount() different custom colors. The custom
1484 colors are shared by all color dialogs, and remembered during the
1485 execution of the program. Use setCustomColor() to set the
1486 custom colors, and customColor() to get them.
1487
1488 <img src=qcolordlg-m.png> <img src=qcolordlg-w.png>
1489*/
1490
1491/*!
1492 Constructs a default color dialog. Use setColor() for setting an initial value.
1493
1494 \sa getColor()
1495*/
1496
1497KColorDialog::KColorDialog(QWidget* parent, const char* name, bool modal) :
1498 QDialog(parent, name, modal )
1499{
1500 setSizeGripEnabled( TRUE );
1501 d = new KColorDialogPrivate( this );
1502}
1503
1504
1505/*!
1506 Pops up a modal color dialog letting the user choose a color and returns
1507 that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels
1508 the dialog. All colors allocated by the dialog will be deallocated
1509 before this function returns.
1510*/
1511
1512QColor KColorDialog::getColor( QColor initial, QWidget *parent,
1513 const char *name )
1514{
1515 int allocContext = QColor::enterAllocContext();
1516 KColorDialog *dlg = new KColorDialog( parent, name, TRUE ); //modal
1517 if ( parent && parent->icon() && !parent->icon()->isNull() )
1518 dlg->setIcon( *parent->icon() );
1519 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
1520 dlg->setIcon( *qApp->mainWidget()->icon() );
1521
1522 dlg->setCaption( KColorDialog::tr( "Select color" ) );
1523 dlg->setColor( initial );
1524 int resultCode = dlg->exec();
1525 QColor::leaveAllocContext();
1526 QColor result;
1527 if ( resultCode == QDialog::Accepted )
1528 result = dlg->color();
1529 QColor::destroyAllocContext(allocContext);
1530 delete dlg;
1531 return result;
1532}
1533
1534
1535/*!
1536 Pops up a modal color dialog, letting the user choose a color and an
1537 alpha channel value. The color+alpha is initially set to \a initial.
1538
1539 If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK,
1540 and FALSE if the user clicked Cancel.
1541
1542 If the user clicks Cancel the \a initial value is returned.
1543*/
1544
1545QRgb KColorDialog::getRgba( QRgb initial, bool *ok,
1546 QWidget *parent, const char* name )
1547{
1548 int allocContext = QColor::enterAllocContext();
1549 KColorDialog *dlg = new KColorDialog( parent, name, TRUE ); //modal
1550 dlg->setColor( initial );
1551 dlg->setSelectedAlpha( qAlpha(initial) );
1552 int resultCode = dlg->exec();
1553 QColor::leaveAllocContext();
1554 QRgb result = initial;
1555 if ( resultCode == QDialog::Accepted ) {
1556 QRgb c = dlg->color().rgb();
1557 int alpha = dlg->selectedAlpha();
1558 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
1559 }
1560 if ( ok )
1561 *ok = resultCode == QDialog::Accepted;
1562
1563 QColor::destroyAllocContext(allocContext);
1564 delete dlg;
1565 return result;
1566}
1567
1568
1569
1570
1571
1572/*!
1573 Returns the color currently selected in the dialog.
1574
1575 \sa setColor()
1576*/
1577
1578QColor KColorDialog::color() const
1579{
1580 return QColor(d->currentColor());
1581}
1582
1583
1584/*! Destructs the dialog and frees any memory it allocated.
1585
1586*/
1587
1588KColorDialog::~KColorDialog()
1589{
1590 //d inherits QObject, so it is deleted by Qt.
1591}
1592
1593
1594/*!
1595 Sets the color shown in the dialog to \a c.
1596
1597 \sa color()
1598*/
1599
1600void KColorDialog::setColor( QColor c )
1601{
1602 d->setCurrentColor( c.rgb() );
1603}
1604
1605
1606
1607
1608/*!
1609 Sets the initial alpha channel value to \a a, and show the alpha channel
1610 entry box.
1611*/
1612
1613void KColorDialog::setSelectedAlpha( int a )
1614{
1615 d->showAlpha( TRUE );
1616 d->setCurrentAlpha( a );
1617}
1618
1619
1620/*!
1621 Returns the value selected for the alpha channel.
1622*/
1623
1624int KColorDialog::selectedAlpha() const
1625{
1626 return d->currentAlpha();
1627}
1628
1629
1630#include "qcolordialog.moc"
1631
diff --git a/noncore/apps/tinykate/libkate/microkde/qcolordialog.h b/noncore/apps/tinykate/libkate/microkde/qcolordialog.h
new file mode 100644
index 0000000..c55dcf4
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/microkde/qcolordialog.h
@@ -0,0 +1,84 @@
1/****************************************************************************
2** $Id$
3**
4** Definition of KColorDialog class
5**
6** Created : 990222
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef KColorDialog_H
39#define KColorDialog_H
40
41#ifndef QT_H
42#include <qdialog.h>
43#endif // QT_H
44
45class KColorDialogPrivate;
46
47class Q_EXPORT KColorDialog : public QDialog
48{
49 Q_OBJECT
50
51public:
52 static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor&
53 static QRgb getRgba( QRgb, bool* ok = 0,
54 QWidget *parent=0, const char* name=0 );
55
56
57 static int customCount();
58 static QRgb customColor( int );
59 static void setCustomColor( int, QRgb );
60
61private:
62 ~KColorDialog();
63
64 KColorDialog( QWidget* parent=0, const char* name=0, bool modal=FALSE );
65 void setColor( QColor ); // ### 3.0: make const QColor&
66 QColor color() const;
67
68private:
69 void setSelectedAlpha( int );
70 int selectedAlpha() const;
71
72 void showCustom( bool=TRUE );
73private:
74 KColorDialogPrivate *d;
75 friend class KColorDialogPrivate;
76
77 private:// Disabled copy constructor and operator=
78#if defined(Q_DISABLE_COPY)
79 KColorDialog( const KColorDialog & );
80 KColorDialog& operator=( const KColorDialog & );
81#endif
82};
83
84#endif //KColorDialog_H
diff --git a/noncore/apps/tinykate/libkate/microkde/xmltree.cc b/noncore/apps/tinykate/libkate/microkde/xmltree.cc
new file mode 100644
index 0000000..27db5b3
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/microkde/xmltree.cc
@@ -0,0 +1,322 @@
1/* This file is part of the KDE project
2 Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20#include <qpe/stringutil.h>
21#include <opie/xmltree.h>
22
23#include <qxml.h>
24
25#include <assert.h>
26
27using namespace Opie;
28
29XMLElement::XMLElement()
30 : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 )
31{
32}
33
34XMLElement::~XMLElement()
35{
36 XMLElement *n = m_first;
37
38 while ( n )
39 {
40 XMLElement *tmp = n;
41 n = n->m_next;
42 delete tmp;
43 }
44}
45
46void XMLElement::appendChild( XMLElement *child )
47{
48 if ( child->m_parent )
49 child->m_parent->removeChild( child );
50
51 child->m_parent = this;
52
53 if ( m_last )
54 m_last->m_next = child;
55
56 child->m_prev = m_last;
57
58 if ( !m_first )
59 m_first = child;
60
61 m_last = child;
62}
63
64void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild )
65{
66 assert( newChild != refChild );
67
68 if ( refChild == m_last )
69 {
70 appendChild( newChild );
71 return;
72 }
73
74 assert( refChild );
75 assert( refChild->m_parent );
76 assert( refChild->m_parent == this );
77
78 if ( newChild->m_parent && newChild != refChild )
79 newChild->m_parent->removeChild( newChild );
80
81 newChild->m_parent = this;
82
83 XMLElement *next = refChild->m_next;
84
85 refChild->m_next = newChild;
86
87 newChild->m_prev = refChild;
88 newChild->m_next = next;
89
90 if ( next )
91 next->m_prev = newChild;
92}
93
94QString XMLElement::attribute( const QString &attr ) const
95{
96 AttributeMap::ConstIterator it = m_attributes.find( attr );
97 if ( it == m_attributes.end() )
98 return QString::null;
99 return it.data();
100}
101
102void XMLElement::setAttribute( const QString &attr, const QString &value )
103{
104 m_attributes.replace( attr, value );
105}
106
107void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild )
108{
109 assert( refChild );
110 assert( refChild->m_parent );
111 assert( refChild->m_parent == this );
112 assert( newChild != refChild );
113
114 if ( newChild->m_parent && newChild != refChild )
115 newChild->m_parent->removeChild( newChild );
116
117 newChild->m_parent = this;
118
119 XMLElement *prev = refChild->m_prev;
120
121 refChild->m_prev = newChild;
122
123 newChild->m_prev = prev;
124 newChild->m_next = refChild;
125
126 if ( prev )
127 prev->m_next = newChild;
128
129 if ( refChild == m_first )
130 m_first = newChild;
131}
132
133void XMLElement::removeChild( XMLElement *child )
134{
135 if ( child->m_parent != this )
136 return;
137
138 if ( m_first == child )
139 m_first = child->m_next;
140
141 if ( m_last == child )
142 m_last = child->m_prev;
143
144 if ( child->m_prev )
145 child->m_prev->m_next = child->m_next;
146
147 if ( child->m_next )
148 child->m_next->m_prev = child->m_prev;
149
150 child->m_parent = 0;
151 child->m_prev = 0;
152 child->m_next = 0;
153}
154
155void XMLElement::save( QTextStream &s, uint indent )
156{
157 if ( !m_value.isEmpty() )
158 {
159 s << Qtopia::escapeString( m_value );
160 return;
161 }
162
163 for ( uint i = 0; i < indent; ++i )
164 s << " ";
165
166 s << "<" << m_tag;
167
168 if ( !m_attributes.isEmpty() )
169 {
170 s << " ";
171 AttributeMap::ConstIterator it = m_attributes.begin();
172 AttributeMap::ConstIterator end = m_attributes.end();
173 for (; it != end; ++it )
174 {
175 s << it.key() << "=\"" << Qtopia::escapeString( it.data() ) << "\"";
176 s << " ";
177 }
178 }
179
180 if ( m_last )
181 {
182 if ( ( m_first && !m_first->value().isEmpty() ) || !m_parent )
183 s << ">";
184 else
185 s << ">" << endl;
186
187 int newIndent = indent;
188 if ( m_parent )
189 newIndent++;
190
191 XMLElement *n = m_first;
192 while ( n )
193 {
194 n->save( s, newIndent );
195 n = n->nextChild();
196 }
197
198 if ( m_last && m_last->value().isEmpty() && m_parent )
199 for ( uint i = 0; i < indent; ++i )
200 s << " ";
201
202 if ( m_parent )
203 s << "</" << m_tag << ">" << endl;
204 }
205 else
206 s << "/>" << endl;
207}
208
209class Handler : public QXmlDefaultHandler
210{
211public:
212 Handler() : m_node( 0 ), m_root( 0 ) {}
213
214 XMLElement *root() const { return m_root; }
215
216 virtual bool startDocument();
217 virtual bool endDocument();
218 virtual bool startElement( const QString &ns, const QString &ln, const QString &qName,
219 const QXmlAttributes &attr );
220 virtual bool endElement( const QString &ns, const QString &ln, const QString &qName );
221 virtual bool characters( const QString &ch );
222
223private:
224 XMLElement *m_node;
225 XMLElement *m_root;
226};
227
228bool Handler::startDocument()
229{
230 m_root = m_node = new XMLElement;
231
232 return true;
233}
234
235bool Handler::endDocument()
236{
237 return m_root == m_node;
238}
239
240bool Handler::startElement( const QString &, const QString &, const QString &qName,
241 const QXmlAttributes &attr )
242{
243 XMLElement *bm = new XMLElement;
244
245 XMLElement::AttributeMap attributes;
246 for ( int i = 0; i < attr.length(); ++i )
247 attributes[ attr.qName( i ) ] = attr.value( i );
248
249 bm->setAttributes( attributes );
250
251 bm->setTagName( qName );
252
253 m_node->appendChild( bm );
254 m_node = bm;
255
256 return true;
257}
258
259bool Handler::endElement( const QString &, const QString &, const QString & )
260{
261 if ( m_node == m_root )
262 return false;
263
264 m_node = m_node->parent();
265 return true;
266}
267
268bool Handler::characters( const QString &ch )
269{
270 XMLElement *textNode = new XMLElement;
271 textNode->setValue( ch );
272 m_node->appendChild( textNode );
273 return true;
274}
275
276XMLElement *XMLElement::namedItem( const QString &name )
277{
278 XMLElement *e = m_first;
279
280 for (; e; e = e->nextChild() )
281 if ( e->tagName() == name )
282 return e;
283
284 return 0;
285}
286
287XMLElement *XMLElement::clone() const
288{
289 XMLElement *res = new XMLElement;
290
291 res->setTagName( m_tag );
292 res->setValue( m_value );
293 res->setAttributes( m_attributes );
294
295 XMLElement *e = m_first;
296 for (; e; e = e->m_next )
297 res->appendChild( e->clone() );
298
299 return res;
300}
301
302XMLElement *XMLElement::load( const QString &fileName )
303{
304 QFile f( fileName );
305 if ( !f.open( IO_ReadOnly ) )
306 return 0;
307
308 QTextStream stream( &f );
309 stream.setEncoding( QTextStream::UnicodeUTF8 );
310 QXmlInputSource src( stream );
311 QXmlSimpleReader reader;
312 Handler handler;
313
314 reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false );
315 reader.setContentHandler( &handler );
316 reader.parse( src );
317
318 return handler.root();;
319}
320
321/* vim: et sw=4
322 */
diff --git a/noncore/apps/tinykate/libkate/microkde/xmltree.h b/noncore/apps/tinykate/libkate/microkde/xmltree.h
new file mode 100644
index 0000000..4a6b6d9
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/microkde/xmltree.h
@@ -0,0 +1,117 @@
1/* This file is part of the KDE project
2 Copyright (C) 2000,2001 Simon Hausmann <hausmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20
21#ifndef __bookmarks_h__
22#define __bookmarks_h__
23
24#include <qstring.h>
25#include <qmap.h>
26#include <qtextstream.h>
27
28namespace Opie
29{
30
31/**
32 * A small xml lib written by Simon Hausmann.
33 */
34class XMLElement
35{
36public:
37 typedef QMap<QString, QString> AttributeMap;
38
39 /**
40 * The constructor of XMLElement
41 */
42 XMLElement();
43 ~XMLElement();
44
45 /** appendChild appends a child to the XMLElement behind the last element.
46 * The ownership of the child get's transfered to the
47 * this XMLElement.
48 * If child is already the child of another parent
49 * it's get removed from the other parent first.
50 */
51 void appendChild( XMLElement *child );
52
53 /** inserts newChild after refChild. If newChild is the child
54 * of another parent the child will get removed.
55 * The ownership of child gets transfered.
56 *
57 */
58 void insertAfter( XMLElement *newChild, XMLElement *refChild );
59
60 /** same as insertAfter but the element get's inserted before refChild.
61 *
62 */
63 void insertBefore( XMLElement *newChild, XMLElement *refChild );
64
65 /** removeChild removes the child from the XMLElement.
66 * The ownership gets dropped. You need to delete the
67 * child yourself.
68 */
69 void removeChild( XMLElement *child );
70
71 /** parent() returns the parent of this XMLElement
72 * If there is no parent 0l gets returned
73 */
74 XMLElement *parent() const { return m_parent; }
75 XMLElement *firstChild() const { return m_first; }
76 XMLElement *nextChild() const { return m_next; }
77 XMLElement *prevChild() const { return m_prev; }
78 XMLElement *lastChild() const { return m_last; }
79
80 void setTagName( const QString &tag ) { m_tag = tag; }
81 QString tagName() const { return m_tag; }
82
83 void setValue( const QString &val ) { m_value = val; }
84 QString value() const { return m_value; }
85
86 void setAttributes( const AttributeMap &attrs ) { m_attributes = attrs; }
87 AttributeMap attributes() const { return m_attributes; }
88 AttributeMap &attributes() { return m_attributes; }
89
90 QString attribute( const QString & ) const;
91 void setAttribute( const QString &attr, const QString &value );
92 void save( QTextStream &stream, uint indent = 0 );
93
94 XMLElement *namedItem( const QString &name );
95
96 XMLElement *clone() const;
97
98 static XMLElement *load( const QString &fileName );
99
100private:
101 QString m_tag;
102 QString m_value;
103 AttributeMap m_attributes;
104
105 XMLElement *m_parent;
106 XMLElement *m_next;
107 XMLElement *m_prev;
108 XMLElement *m_first;
109 XMLElement *m_last;
110
111 XMLElement( const XMLElement &rhs );
112 XMLElement &operator=( const XMLElement &rhs );
113};
114
115} // namespace Opie
116
117#endif
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp
index af3b30d..de81d0f 100644
--- a/noncore/apps/tinykate/libkate/view/kateview.cpp
+++ b/noncore/apps/tinykate/libkate/view/kateview.cpp
@@ -1815,900 +1815,902 @@ void KateView::doEditCommand(int cmdNum) {
1815 VConfig c; 1815 VConfig c;
1816 myViewInternal->getVConfig(c); 1816 myViewInternal->getVConfig(c);
1817 myViewInternal->doEditCommand(c, cmdNum); 1817 myViewInternal->doEditCommand(c, cmdNum);
1818 myDoc->updateViews(); 1818 myDoc->updateViews();
1819} 1819}
1820 1820
1821void KateView::undoMultiple(int count) { 1821void KateView::undoMultiple(int count) {
1822 if (isReadOnly()) 1822 if (isReadOnly())
1823 return; 1823 return;
1824 1824
1825 VConfig c; 1825 VConfig c;
1826 myViewInternal->getVConfig(c); 1826 myViewInternal->getVConfig(c);
1827 myDoc->undo(c, count); 1827 myDoc->undo(c, count);
1828 myDoc->updateViews(); 1828 myDoc->updateViews();
1829} 1829}
1830 1830
1831void KateView::redoMultiple(int count) { 1831void KateView::redoMultiple(int count) {
1832 if (isReadOnly()) 1832 if (isReadOnly())
1833 return; 1833 return;
1834 1834
1835 VConfig c; 1835 VConfig c;
1836 myViewInternal->getVConfig(c); 1836 myViewInternal->getVConfig(c);
1837 myDoc->redo(c, count); 1837 myDoc->redo(c, count);
1838 myDoc->updateViews(); 1838 myDoc->updateViews();
1839} 1839}
1840 1840
1841void KateView::undoHistory() 1841void KateView::undoHistory()
1842{ 1842{
1843 UndoHistory *undoH; 1843 UndoHistory *undoH;
1844 1844
1845 undoH = new UndoHistory(this, this, "UndoHistory", true); 1845 undoH = new UndoHistory(this, this, "UndoHistory", true);
1846 1846
1847 undoH->setCaption(i18n("Undo/Redo History")); 1847 undoH->setCaption(i18n("Undo/Redo History"));
1848 1848
1849 connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo())); 1849 connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo()));
1850 connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int))); 1850 connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int)));
1851 connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int))); 1851 connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int)));
1852 1852
1853 undoH->exec(); 1853 undoH->exec();
1854 1854
1855 delete undoH; 1855 delete undoH;
1856} 1856}
1857 1857
1858static void kwview_addToStrList(QStringList &list, const QString &str) { 1858static void kwview_addToStrList(QStringList &list, const QString &str) {
1859 if (list.count() > 0) { 1859 if (list.count() > 0) {
1860 if (list.first() == str) return; 1860 if (list.first() == str) return;
1861 QStringList::Iterator it; 1861 QStringList::Iterator it;
1862 it = list.find(str); 1862 it = list.find(str);
1863 if (*it != 0L) list.remove(it); 1863 if (*it != 0L) list.remove(it);
1864 if (list.count() >= 16) list.remove(list.fromLast()); 1864 if (list.count() >= 16) list.remove(list.fromLast());
1865 } 1865 }
1866 list.prepend(str); 1866 list.prepend(str);
1867} 1867}
1868 1868
1869void KateView::find() { 1869void KateView::find() {
1870 SearchDialog *searchDialog; 1870 SearchDialog *searchDialog;
1871 1871
1872 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; 1872 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
1873 1873
1874 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, 1874 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
1875 searchFlags & ~KateView::sfReplace); 1875 searchFlags & ~KateView::sfReplace);
1876 1876
1877 // If the user has marked some text we use that otherwise 1877 // If the user has marked some text we use that otherwise
1878 // use the word under the cursor. 1878 // use the word under the cursor.
1879 QString str; 1879 QString str;
1880 if (myDoc->hasMarkedText()) 1880 if (myDoc->hasMarkedText())
1881 str = markedText(); 1881 str = markedText();
1882 1882
1883 if (str.isEmpty()) 1883 if (str.isEmpty())
1884 str = currentWord(); 1884 str = currentWord();
1885 1885
1886 if (!str.isEmpty()) 1886 if (!str.isEmpty())
1887 { 1887 {
1888 str.replace(QRegExp("^\n"), ""); 1888 str.replace(QRegExp("^\n"), "");
1889 int pos=str.find("\n"); 1889 int pos=str.find("\n");
1890 if (pos>-1) 1890 if (pos>-1)
1891 str=str.left(pos); 1891 str=str.left(pos);
1892 searchDialog->setSearchText( str ); 1892 searchDialog->setSearchText( str );
1893 } 1893 }
1894 1894
1895 myViewInternal->focusOutEvent(0L);// QT bug ? 1895 myViewInternal->focusOutEvent(0L);// QT bug ?
1896 if (searchDialog->exec() == QDialog::Accepted) { 1896 if (searchDialog->exec() == QDialog::Accepted) {
1897 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); 1897 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
1898 searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt); 1898 searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt);
1899 initSearch(s, searchFlags); 1899 initSearch(s, searchFlags);
1900 findAgain(s); 1900 findAgain(s);
1901 } 1901 }
1902 delete searchDialog; 1902 delete searchDialog;
1903} 1903}
1904 1904
1905void KateView::replace() { 1905void KateView::replace() {
1906 SearchDialog *searchDialog; 1906 SearchDialog *searchDialog;
1907 1907
1908 if (isReadOnly()) return; 1908 if (isReadOnly()) return;
1909 1909
1910 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; 1910 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
1911 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, 1911 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
1912 searchFlags | KateView::sfReplace); 1912 searchFlags | KateView::sfReplace);
1913 1913
1914 // If the user has marked some text we use that otherwise 1914 // If the user has marked some text we use that otherwise
1915 // use the word under the cursor. 1915 // use the word under the cursor.
1916 QString str; 1916 QString str;
1917 if (myDoc->hasMarkedText()) 1917 if (myDoc->hasMarkedText())
1918 str = markedText(); 1918 str = markedText();
1919 1919
1920 if (str.isEmpty()) 1920 if (str.isEmpty())
1921 str = currentWord(); 1921 str = currentWord();
1922 1922
1923 if (!str.isEmpty()) 1923 if (!str.isEmpty())
1924 { 1924 {
1925 str.replace(QRegExp("^\n"), ""); 1925 str.replace(QRegExp("^\n"), "");
1926 int pos=str.find("\n"); 1926 int pos=str.find("\n");
1927 if (pos>-1) 1927 if (pos>-1)
1928 str=str.left(pos); 1928 str=str.left(pos);
1929 searchDialog->setSearchText( str ); 1929 searchDialog->setSearchText( str );
1930 } 1930 }
1931 1931
1932 myViewInternal->focusOutEvent(0L);// QT bug ? 1932 myViewInternal->focusOutEvent(0L);// QT bug ?
1933 if (searchDialog->exec() == QDialog::Accepted) { 1933 if (searchDialog->exec() == QDialog::Accepted) {
1934// myDoc->recordReset(); 1934// myDoc->recordReset();
1935 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); 1935 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
1936 kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith()); 1936 kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith());
1937 searchFlags = searchDialog->getFlags(); 1937 searchFlags = searchDialog->getFlags();
1938 initSearch(s, searchFlags); 1938 initSearch(s, searchFlags);
1939 replaceAgain(); 1939 replaceAgain();
1940 } 1940 }
1941 delete searchDialog; 1941 delete searchDialog;
1942} 1942}
1943 1943
1944void KateView::gotoLine() { 1944void KateView::gotoLine() {
1945 GotoLineDialog *dlg; 1945 GotoLineDialog *dlg;
1946 PointStruc cursor; 1946 PointStruc cursor;
1947 1947
1948 dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines()); 1948 dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines());
1949// dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this); 1949// dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this);
1950 1950
1951 if (dlg->exec() == QDialog::Accepted) { 1951 if (dlg->exec() == QDialog::Accepted) {
1952// myDoc->recordReset(); 1952// myDoc->recordReset();
1953 cursor.x = 0; 1953 cursor.x = 0;
1954 cursor.y = dlg->getLine() - 1; 1954 cursor.y = dlg->getLine() - 1;
1955 myDoc->needPreHighlight(cursor.y); 1955 myDoc->needPreHighlight(cursor.y);
1956 myViewInternal->updateCursor(cursor); 1956 myViewInternal->updateCursor(cursor);
1957 myViewInternal->center(); 1957 myViewInternal->center();
1958 myViewInternal->updateView(KateView::ufUpdateOnScroll); 1958 myViewInternal->updateView(KateView::ufUpdateOnScroll);
1959 myDoc->updateViews(this); //uptade all other views except this one 1959 myDoc->updateViews(this); //uptade all other views except this one
1960 } 1960 }
1961 delete dlg; 1961 delete dlg;
1962} 1962}
1963 1963
1964 1964
1965void KateView::initSearch(SConfig &s, int flags) { 1965void KateView::initSearch(SConfig &s, int flags) {
1966 1966
1967 s.flags = flags; 1967 s.flags = flags;
1968 s.setPattern(myDoc->searchForList.first()); 1968 s.setPattern(myDoc->searchForList.first());
1969 1969
1970 if (!(s.flags & KateView::sfFromBeginning)) { 1970 if (!(s.flags & KateView::sfFromBeginning)) {
1971 // If we are continuing a backward search, make sure we do not get stuck 1971 // If we are continuing a backward search, make sure we do not get stuck
1972 // at an existing match. 1972 // at an existing match.
1973 s.cursor = myViewInternal->cursor; 1973 s.cursor = myViewInternal->cursor;
1974 TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y); 1974 TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y);
1975 QString const txt(textLine->getText(),textLine->length()); 1975 QString const txt(textLine->getText(),textLine->length());
1976 const QString searchFor= myDoc->searchForList.first(); 1976 const QString searchFor= myDoc->searchForList.first();
1977 int pos = s.cursor.x-searchFor.length()-1; 1977 int pos = s.cursor.x-searchFor.length()-1;
1978 if ( pos < 0 ) pos = 0; 1978 if ( pos < 0 ) pos = 0;
1979 pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive); 1979 pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive);
1980 if ( s.flags & KateView::sfBackward ) 1980 if ( s.flags & KateView::sfBackward )
1981 { 1981 {
1982 if ( pos <= s.cursor.x ) s.cursor.x= pos-1; 1982 if ( pos <= s.cursor.x ) s.cursor.x= pos-1;
1983 } 1983 }
1984 else 1984 else
1985 if ( pos == s.cursor.x ) s.cursor.x++; 1985 if ( pos == s.cursor.x ) s.cursor.x++;
1986 } else { 1986 } else {
1987 if (!(s.flags & KateView::sfBackward)) { 1987 if (!(s.flags & KateView::sfBackward)) {
1988 s.cursor.x = 0; 1988 s.cursor.x = 0;
1989 s.cursor.y = 0; 1989 s.cursor.y = 0;
1990 } else { 1990 } else {
1991 s.cursor.x = -1; 1991 s.cursor.x = -1;
1992 s.cursor.y = myDoc->lastLine(); 1992 s.cursor.y = myDoc->lastLine();
1993 } 1993 }
1994 s.flags |= KateView::sfFinished; 1994 s.flags |= KateView::sfFinished;
1995 } 1995 }
1996 if (!(s.flags & KateView::sfBackward)) { 1996 if (!(s.flags & KateView::sfBackward)) {
1997 if (!(s.cursor.x || s.cursor.y)) 1997 if (!(s.cursor.x || s.cursor.y))
1998 s.flags |= KateView::sfFinished; 1998 s.flags |= KateView::sfFinished;
1999 } 1999 }
2000 s.startCursor = s.cursor; 2000 s.startCursor = s.cursor;
2001} 2001}
2002 2002
2003void KateView::continueSearch(SConfig &s) { 2003void KateView::continueSearch(SConfig &s) {
2004 2004
2005 if (!(s.flags & KateView::sfBackward)) { 2005 if (!(s.flags & KateView::sfBackward)) {
2006 s.cursor.x = 0; 2006 s.cursor.x = 0;
2007 s.cursor.y = 0; 2007 s.cursor.y = 0;
2008 } else { 2008 } else {
2009 s.cursor.x = -1; 2009 s.cursor.x = -1;
2010 s.cursor.y = myDoc->lastLine(); 2010 s.cursor.y = myDoc->lastLine();
2011 } 2011 }
2012 s.flags |= KateView::sfFinished; 2012 s.flags |= KateView::sfFinished;
2013 s.flags &= ~KateView::sfAgain; 2013 s.flags &= ~KateView::sfAgain;
2014} 2014}
2015 2015
2016void KateView::findAgain(SConfig &s) { 2016void KateView::findAgain(SConfig &s) {
2017 int query; 2017 int query;
2018 PointStruc cursor; 2018 PointStruc cursor;
2019 QString str; 2019 QString str;
2020 2020
2021 QString searchFor = myDoc->searchForList.first(); 2021 QString searchFor = myDoc->searchForList.first();
2022 2022
2023 if( searchFor.isEmpty() ) { 2023 if( searchFor.isEmpty() ) {
2024 find(); 2024 find();
2025 return; 2025 return;
2026 } 2026 }
2027 2027
2028 do { 2028 do {
2029 query = KMessageBox::Cancel; 2029 query = KMessageBox::Cancel;
2030 if (myDoc->doSearch(s,searchFor)) { 2030 if (myDoc->doSearch(s,searchFor)) {
2031 cursor = s.cursor; 2031 cursor = s.cursor;
2032 if (!(s.flags & KateView::sfBackward)) 2032 if (!(s.flags & KateView::sfBackward))
2033 s.cursor.x += s.matchedLength; 2033 s.cursor.x += s.matchedLength;
2034 myViewInternal->updateCursor(s.cursor); //does deselectAll() 2034 myViewInternal->updateCursor(s.cursor); //does deselectAll()
2035 exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false); 2035 exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false);
2036 } else { 2036 } else {
2037 if (!(s.flags & KateView::sfFinished)) { 2037 if (!(s.flags & KateView::sfFinished)) {
2038 // ask for continue 2038 // ask for continue
2039 if (!(s.flags & KateView::sfBackward)) { 2039 if (!(s.flags & KateView::sfBackward)) {
2040 // forward search 2040 // forward search
2041 str = i18n("End of document reached.\n" 2041 str = i18n("End of document reached.\n"
2042 "Continue from the beginning?"); 2042 "Continue from the beginning?");
2043 query = KMessageBox::warningContinueCancel(this, 2043 query = KMessageBox::warningContinueCancel(this,
2044 str, i18n("Find"), i18n("Continue")); 2044 str, i18n("Find"), i18n("Continue"));
2045 } else { 2045 } else {
2046 // backward search 2046 // backward search
2047 str = i18n("Beginning of document reached.\n" 2047 str = i18n("Beginning of document reached.\n"
2048 "Continue from the end?"); 2048 "Continue from the end?");
2049 query = KMessageBox::warningContinueCancel(this, 2049 query = KMessageBox::warningContinueCancel(this,
2050 str, i18n("Find"), i18n("Continue")); 2050 str, i18n("Find"), i18n("Continue"));
2051 } 2051 }
2052 continueSearch(s); 2052 continueSearch(s);
2053 } else { 2053 } else {
2054 // wrapped 2054 // wrapped
2055 KMessageBox::sorry(this, 2055 KMessageBox::sorry(this,
2056 i18n("Search string '%1' not found!").arg(searchFor), 2056 i18n("Search string '%1' not found!").arg(searchFor),
2057 i18n("Find")); 2057 i18n("Find"));
2058 } 2058 }
2059 } 2059 }
2060 } while (query == KMessageBox::Continue); 2060 } while (query == KMessageBox::Continue);
2061} 2061}
2062 2062
2063void KateView::replaceAgain() { 2063void KateView::replaceAgain() {
2064 if (isReadOnly()) 2064 if (isReadOnly())
2065 return; 2065 return;
2066 2066
2067 replaces = 0; 2067 replaces = 0;
2068 if (s.flags & KateView::sfPrompt) { 2068 if (s.flags & KateView::sfPrompt) {
2069 doReplaceAction(-1); 2069 doReplaceAction(-1);
2070 } else { 2070 } else {
2071 doReplaceAction(KateView::srAll); 2071 doReplaceAction(KateView::srAll);
2072 } 2072 }
2073} 2073}
2074 2074
2075void KateView::doReplaceAction(int result, bool found) { 2075void KateView::doReplaceAction(int result, bool found) {
2076 int rlen; 2076 int rlen;
2077 PointStruc cursor; 2077 PointStruc cursor;
2078 bool started; 2078 bool started;
2079 2079
2080 QString searchFor = myDoc->searchForList.first(); 2080 QString searchFor = myDoc->searchForList.first();
2081 QString replaceWith = myDoc->replaceWithList.first(); 2081 QString replaceWith = myDoc->replaceWithList.first();
2082 rlen = replaceWith.length(); 2082 rlen = replaceWith.length();
2083 2083
2084 switch (result) { 2084 switch (result) {
2085 case KateView::srYes: //yes 2085 case KateView::srYes: //yes
2086 myDoc->recordStart(this, s.cursor, configFlags, 2086 myDoc->recordStart(this, s.cursor, configFlags,
2087 KateActionGroup::ugReplace, true); 2087 KateActionGroup::ugReplace, true);
2088 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); 2088 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
2089 replaces++; 2089 replaces++;
2090 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) 2090 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
2091 s.startCursor.x += rlen - s.matchedLength; 2091 s.startCursor.x += rlen - s.matchedLength;
2092 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; 2092 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
2093 myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent); 2093 myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent);
2094 break; 2094 break;
2095 case KateView::srNo: //no 2095 case KateView::srNo: //no
2096 if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength; 2096 if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength;
2097 break; 2097 break;
2098 case KateView::srAll: //replace all 2098 case KateView::srAll: //replace all
2099 deleteReplacePrompt(); 2099 deleteReplacePrompt();
2100 do { 2100 do {
2101 started = false; 2101 started = false;
2102 while (found || myDoc->doSearch(s,searchFor)) { 2102 while (found || myDoc->doSearch(s,searchFor)) {
2103 if (!started) { 2103 if (!started) {
2104 found = false; 2104 found = false;
2105 myDoc->recordStart(this, s.cursor, configFlags, 2105 myDoc->recordStart(this, s.cursor, configFlags,
2106 KateActionGroup::ugReplace); 2106 KateActionGroup::ugReplace);
2107 started = true; 2107 started = true;
2108 } 2108 }
2109 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); 2109 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
2110 replaces++; 2110 replaces++;
2111 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) 2111 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
2112 s.startCursor.x += rlen - s.matchedLength; 2112 s.startCursor.x += rlen - s.matchedLength;
2113 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; 2113 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
2114 } 2114 }
2115 if (started) myDoc->recordEnd(this, s.cursor, 2115 if (started) myDoc->recordEnd(this, s.cursor,
2116 configFlags | KateView::cfPersistent); 2116 configFlags | KateView::cfPersistent);
2117 } while (!askReplaceEnd()); 2117 } while (!askReplaceEnd());
2118 return; 2118 return;
2119 case KateView::srCancel: //cancel 2119 case KateView::srCancel: //cancel
2120 deleteReplacePrompt(); 2120 deleteReplacePrompt();
2121 return; 2121 return;
2122 default: 2122 default:
2123 replacePrompt = 0L; 2123 replacePrompt = 0L;
2124 } 2124 }
2125 2125
2126 do { 2126 do {
2127 if (myDoc->doSearch(s,searchFor)) { 2127 if (myDoc->doSearch(s,searchFor)) {
2128 //text found: highlight it, show replace prompt if needed and exit 2128 //text found: highlight it, show replace prompt if needed and exit
2129 cursor = s.cursor; 2129 cursor = s.cursor;
2130 if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength; 2130 if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength;
2131 myViewInternal->updateCursor(cursor); //does deselectAll() 2131 myViewInternal->updateCursor(cursor); //does deselectAll()
2132 exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true); 2132 exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true);
2133 if (replacePrompt == 0L) { 2133 if (replacePrompt == 0L) {
2134 replacePrompt = new ReplacePrompt(this); 2134 replacePrompt = new ReplacePrompt(this);
2135 myDoc->setPseudoModal(replacePrompt);//disable(); 2135 myDoc->setPseudoModal(replacePrompt);//disable();
2136 connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot())); 2136 connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot()));
2137 replacePrompt->show(); //this is not modal 2137 replacePrompt->show(); //this is not modal
2138 } 2138 }
2139 return; //exit if text found 2139 return; //exit if text found
2140 } 2140 }
2141 //nothing found: repeat until user cancels "repeat from beginning" dialog 2141 //nothing found: repeat until user cancels "repeat from beginning" dialog
2142 } while (!askReplaceEnd()); 2142 } while (!askReplaceEnd());
2143 deleteReplacePrompt(); 2143 deleteReplacePrompt();
2144} 2144}
2145 2145
2146void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) { 2146void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) {
2147 int x1, x2, y1, y2, xPos, yPos; 2147 int x1, x2, y1, y2, xPos, yPos;
2148 2148
2149 VConfig c; 2149 VConfig c;
2150 myViewInternal->getVConfig(c); 2150 myViewInternal->getVConfig(c);
2151 myDoc->selectLength(cursor,slen,c.flags); 2151 myDoc->selectLength(cursor,slen,c.flags);
2152 2152
2153 TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); 2153 TextLine::Ptr textLine = myDoc->getTextLine(cursor.y);
2154 x1 = myDoc->textWidth(textLine,cursor.x) -10; 2154 x1 = myDoc->textWidth(textLine,cursor.x) -10;
2155 x2 = myDoc->textWidth(textLine,cursor.x + slen) +20; 2155 x2 = myDoc->textWidth(textLine,cursor.x + slen) +20;
2156 y1 = myDoc->fontHeight*cursor.y -10; 2156 y1 = myDoc->fontHeight*cursor.y -10;
2157 y2 = y1 + myDoc->fontHeight +30; 2157 y2 = y1 + myDoc->fontHeight +30;
2158 2158
2159 xPos = myViewInternal->xPos; 2159 xPos = myViewInternal->xPos;
2160 yPos = myViewInternal->yPos; 2160 yPos = myViewInternal->yPos;
2161 2161
2162 if (x1 < 0) x1 = 0; 2162 if (x1 < 0) x1 = 0;
2163 if (replace) y2 += 90; 2163 if (replace) y2 += 90;
2164 2164
2165 if (x1 < xPos || x2 > xPos + myViewInternal->width()) { 2165 if (x1 < xPos || x2 > xPos + myViewInternal->width()) {
2166 xPos = x2 - myViewInternal->width(); 2166 xPos = x2 - myViewInternal->width();
2167 } 2167 }
2168 if (y1 < yPos || y2 > yPos + myViewInternal->height()) { 2168 if (y1 < yPos || y2 > yPos + myViewInternal->height()) {
2169 xPos = x2 - myViewInternal->width(); 2169 xPos = x2 - myViewInternal->width();
2170 yPos = myDoc->fontHeight*cursor.y - height()/3; 2170 yPos = myDoc->fontHeight*cursor.y - height()/3;
2171 } 2171 }
2172 myViewInternal->setPos(xPos, yPos); 2172 myViewInternal->setPos(xPos, yPos);
2173 myViewInternal->updateView(flags);// | ufPos,xPos,yPos); 2173 myViewInternal->updateView(flags);// | ufPos,xPos,yPos);
2174 myDoc->updateViews(this); 2174 myDoc->updateViews(this);
2175} 2175}
2176 2176
2177void KateView::deleteReplacePrompt() { 2177void KateView::deleteReplacePrompt() {
2178 myDoc->setPseudoModal(0L); 2178 myDoc->setPseudoModal(0L);
2179} 2179}
2180 2180
2181bool KateView::askReplaceEnd() { 2181bool KateView::askReplaceEnd() {
2182 QString str; 2182 QString str;
2183 int query; 2183 int query;
2184 2184
2185 myDoc->updateViews(); 2185 myDoc->updateViews();
2186 if (s.flags & KateView::sfFinished) { 2186 if (s.flags & KateView::sfFinished) {
2187 // replace finished 2187 // replace finished
2188 str = i18n("%1 replacement(s) made").arg(replaces); 2188 str = i18n("%1 replacement(s) made").arg(replaces);
2189 KMessageBox::information(this, str, i18n("Replace")); 2189 KMessageBox::information(this, str, i18n("Replace"));
2190 return true; 2190 return true;
2191 } 2191 }
2192 2192
2193 // ask for continue 2193 // ask for continue
2194 if (!(s.flags & KateView::sfBackward)) { 2194 if (!(s.flags & KateView::sfBackward)) {
2195 // forward search 2195 // forward search
2196 str = i18n("%1 replacement(s) made.\n" 2196 str = i18n("%1 replacement(s) made.\n"
2197 "End of document reached.\n" 2197 "End of document reached.\n"
2198 "Continue from the beginning?").arg(replaces); 2198 "Continue from the beginning?").arg(replaces);
2199 query = KMessageBox::questionYesNo(this, str, i18n("Replace"), 2199 query = KMessageBox::questionYesNo(this, str, i18n("Continue"), i18n("Stop"));
2200 i18n("Continue"), i18n("Stop"));
2201 } else { 2200 } else {
2202 // backward search 2201 // backward search
2203 str = i18n("%1 replacement(s) made.\n" 2202 str = i18n("%1 replacement(s) made.\n"
2204 "Beginning of document reached.\n" 2203 "Beginning of document reached.\n"
2205 "Continue from the end?").arg(replaces); 2204 "Continue from the end?").arg(replaces);
2206 query = KMessageBox::questionYesNo(this, str, i18n("Replace"), 2205 query = KMessageBox::questionYesNo(this, str, i18n("Continue"), i18n("Stop"));
2207 i18n("Continue"), i18n("Stop"));
2208 } 2206 }
2209 replaces = 0; 2207 replaces = 0;
2210 continueSearch(s); 2208 continueSearch(s);
2211 return (query == KMessageBox::No); 2209 return (query == KMessageBox::No);
2212} 2210}
2213 2211
2214void KateView::replaceSlot() { 2212void KateView::replaceSlot() {
2215 doReplaceAction(replacePrompt->result(),true); 2213 doReplaceAction(replacePrompt->result(),true);
2216} 2214}
2217 2215
2218void KateView::installPopup(QPopupMenu *rmb_Menu) 2216void KateView::installPopup(QPopupMenu *rmb_Menu)
2219{ 2217{
2220 rmbMenu = rmb_Menu; 2218 rmbMenu = rmb_Menu;
2221} 2219}
2222 2220
2223void KateView::readConfig() 2221void KateView::readConfig()
2224{ 2222{
2225 KateConfig *config = KGlobal::config(); 2223 KateConfig *config = KGlobal::config();
2226 config->setGroup("Kate View"); 2224 config->setGroup("Kate View");
2227 2225
2228 searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt); 2226 searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt);
2229 configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark; 2227 configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark;
2230 2228
2231// config->sync(); 2229// config->sync();
2232} 2230}
2233 2231
2234void KateView::writeConfig() 2232void KateView::writeConfig()
2235{ 2233{
2236 KateConfig *config = KGlobal::config(); 2234 KateConfig *config = KGlobal::config();
2237 config->setGroup("Kate View"); 2235 config->setGroup("Kate View");
2238 2236
2239 config->writeEntry("SearchFlags",searchFlags); 2237 config->writeEntry("SearchFlags",searchFlags);
2240 config->writeEntry("ConfigFlags",configFlags); 2238 config->writeEntry("ConfigFlags",configFlags);
2241 2239
2242// config->sync(); 2240// config->sync();
2243} 2241}
2244 2242
2245void KateView::readSessionConfig(KateConfig *config) 2243void KateView::readSessionConfig(KateConfig *config)
2246{ 2244{
2247 PointStruc cursor; 2245 PointStruc cursor;
2248 2246
2249 myViewInternal->xPos = config->readNumEntry("XPos"); 2247 myViewInternal->xPos = config->readNumEntry("XPos");
2250 myViewInternal->yPos = config->readNumEntry("YPos"); 2248 myViewInternal->yPos = config->readNumEntry("YPos");
2251 cursor.x = config->readNumEntry("CursorX"); 2249 cursor.x = config->readNumEntry("CursorX");
2252 cursor.y = config->readNumEntry("CursorY"); 2250 cursor.y = config->readNumEntry("CursorY");
2253 myViewInternal->updateCursor(cursor); 2251 myViewInternal->updateCursor(cursor);
2254 myIconBorder = config->readBoolEntry("IconBorder on"); 2252 myIconBorder = config->readBoolEntry("IconBorder on");
2255 setIconBorder(myIconBorder); 2253 setIconBorder(myIconBorder);
2256} 2254}
2257 2255
2258void KateView::writeSessionConfig(KateConfig *config) 2256void KateView::writeSessionConfig(KateConfig *config)
2259{ 2257{
2260 config->writeEntry("XPos",myViewInternal->xPos); 2258 config->writeEntry("XPos",myViewInternal->xPos);
2261 config->writeEntry("YPos",myViewInternal->yPos); 2259 config->writeEntry("YPos",myViewInternal->yPos);
2262 config->writeEntry("CursorX",myViewInternal->cursor.x); 2260 config->writeEntry("CursorX",myViewInternal->cursor.x);
2263 config->writeEntry("CursorY",myViewInternal->cursor.y); 2261 config->writeEntry("CursorY",myViewInternal->cursor.y);
2264 config->writeEntry("IconBorder on", myIconBorder); 2262 config->writeEntry("IconBorder on", myIconBorder);
2265} 2263}
2266 2264
2267void KateView::configDialog() 2265void KateView::configDialog()
2268{ 2266{
2269 2267
2270#warning fixme 2268#warning fixme
2269 QScrollView *pScroll;
2271 2270
2272#if 1 2271#if 1
2273 KDialogBase *kd = new KDialogBase(KDialogBase::IconList, 2272 KDialogBase *kd = new KDialogBase(KDialogBase::IconList,
2274 i18n("Configure Editor"), 2273 i18n("Configure Editor"),
2275 KDialogBase::Ok | KDialogBase::Cancel | 2274 KDialogBase::Ok | KDialogBase::Cancel |
2276 KDialogBase::Help , 2275 KDialogBase::Help ,
2277 KDialogBase::Ok, this, "tabdialog"); 2276 KDialogBase::Ok, this, "tabdialog");
2278 2277
2279 // color options 2278 // color options
2280 QFrame *page=kd->addPage(i18n("Colors")); 2279 QFrame *page=kd->addPage(i18n("Colors"));
2281 (new QVBoxLayout(page))->setAutoAdd(true); 2280 (new QVBoxLayout(page))->setAutoAdd(true);
2282 ColorConfig *colorConfig = new ColorConfig(page); 2281 ColorConfig *colorConfig = new ColorConfig(page);
2283 QColor* colors = getColors(); 2282 QColor* colors = getColors();
2284 colorConfig->setColors(colors); 2283 colorConfig->setColors(colors);
2285 2284
2286 page = kd->addPage(i18n("Fonts")); 2285 page = kd->addPage(i18n("Fonts"));
2287 (new QVBoxLayout(page))->setAutoAdd(true); 2286 (new QVBoxLayout(page))->setAutoAdd(true);
2288 2287
2289 FontConfig *fontConfig = new FontConfig(page); 2288 FontConfig *fontConfig = new FontConfig(page);
2290 fontConfig->setFont (myDoc->getFont()); 2289 fontConfig->setFont (myDoc->getFont());
2291 2290
2292 // indent options 2291 // indent options
2293 page=kd->addPage(i18n("Indent")); 2292 page=kd->addPage(i18n("Indent"));
2294 (new QVBoxLayout(page))->setAutoAdd(true); 2293 (new QVBoxLayout(page))->setAutoAdd(true);
2295 2294
2296 IndentConfigTab *indentConfig = new IndentConfigTab(page, this); 2295 IndentConfigTab *indentConfig = new IndentConfigTab(page, this);
2297 2296
2298 // select options 2297 // select options
2299 page=kd->addPage(i18n("Select")); 2298 page=kd->addPage(i18n("Select"));
2300 (new QVBoxLayout(page))->setAutoAdd(true); 2299 (new QVBoxLayout(page))->setAutoAdd(true);
2301 2300
2302 SelectConfigTab *selectConfig = new SelectConfigTab(page, this); 2301 SelectConfigTab *selectConfig = new SelectConfigTab(page, this);
2303 2302
2304 // edit options 2303 // edit options
2305 page=kd->addPage(i18n("Edit")); 2304 page=kd->addPage(i18n("Edit"));
2306 (new QVBoxLayout(page))->setAutoAdd(true); 2305 (new QVBoxLayout(page))->setAutoAdd(true);
2307 2306 pScroll=new QScrollView(page);
2308 EditConfigTab *editConfig = new EditConfigTab(page, this); 2307 EditConfigTab *editConfig = new EditConfigTab(page, this);
2308 pScroll->addChild(editConfig);
2309 2309
2310 2310
2311 2311
2312 HighlightDialogPage *hlPage; 2312 HighlightDialogPage *hlPage;
2313 HlManager *hlManager; 2313 HlManager *hlManager;
2314 HlDataList hlDataList; 2314 HlDataList hlDataList;
2315 ItemStyleList defaultStyleList; 2315 ItemStyleList defaultStyleList;
2316 2316
2317 hlManager = HlManager::self(); 2317 hlManager = HlManager::self();
2318 2318
2319 defaultStyleList.setAutoDelete(true); 2319 defaultStyleList.setAutoDelete(true);
2320 hlManager->getDefaults(defaultStyleList); 2320 hlManager->getDefaults(defaultStyleList);
2321 2321
2322 hlDataList.setAutoDelete(true); 2322 hlDataList.setAutoDelete(true);
2323 //this gets the data from the KateConfig object 2323 //this gets the data from the KateConfig object
2324 hlManager->getHlDataList(hlDataList); 2324 hlManager->getHlDataList(hlDataList);
2325 2325
2326 page=kd->addPage(i18n("Highlighting")); 2326 page=kd->addPage(i18n("Highlighting"));
2327 (new QVBoxLayout(page))->setAutoAdd(true); 2327 (new QVBoxLayout(page))->setAutoAdd(true);
2328 pScroll=new QScrollView(page);
2329 hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, pScroll->viewport());
2330 pScroll->addChild(hlPage);
2328 2331
2329 hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, page); 2332 kd->showMaximized();
2330 kd->showMaximized();
2331 if (kd->exec()) { 2333 if (kd->exec()) {
2332 // color options 2334 // color options
2333 colorConfig->getColors(colors); 2335 colorConfig->getColors(colors);
2334 myDoc->setFont (fontConfig->getFont()); 2336 myDoc->setFont (fontConfig->getFont());
2335 2337
2336 applyColors(); 2338 applyColors();
2337 // indent options 2339 // indent options
2338 indentConfig->getData(this); 2340 indentConfig->getData(this);
2339 // select options 2341 // select options
2340 selectConfig->getData(this); 2342 selectConfig->getData(this);
2341 // edit options 2343 // edit options
2342 editConfig->getData(this); 2344 editConfig->getData(this);
2343 // spell checker 2345 // spell checker
2344 hlManager->setHlDataList(hlDataList); 2346 hlManager->setHlDataList(hlDataList);
2345 hlManager->setDefaults(defaultStyleList); 2347 hlManager->setDefaults(defaultStyleList);
2346 hlPage->saveData(); 2348 hlPage->saveData();
2347 } 2349 }
2348 2350
2349// delete kd; 2351// delete kd;
2350 2352
2351#endif 2353#endif
2352} 2354}
2353 2355
2354int KateView::getHl() { 2356int KateView::getHl() {
2355 return myDoc->highlightNum(); 2357 return myDoc->highlightNum();
2356} 2358}
2357 2359
2358void KateView::setDontChangeHlOnSave() 2360void KateView::setDontChangeHlOnSave()
2359{ 2361{
2360 myDoc->setDontChangeHlOnSave(); 2362 myDoc->setDontChangeHlOnSave();
2361} 2363}
2362 2364
2363void KateView::setHl(int n) { 2365void KateView::setHl(int n) {
2364 myDoc->setHighlight(n); 2366 myDoc->setHighlight(n);
2365 myDoc->setDontChangeHlOnSave(); 2367 myDoc->setDontChangeHlOnSave();
2366 myDoc->updateViews(); 2368 myDoc->updateViews();
2367} 2369}
2368 2370
2369int KateView::getEol() { 2371int KateView::getEol() {
2370 return myDoc->eolMode; 2372 return myDoc->eolMode;
2371} 2373}
2372 2374
2373void KateView::setEol(int eol) { 2375void KateView::setEol(int eol) {
2374 if (isReadOnly()) 2376 if (isReadOnly())
2375 return; 2377 return;
2376 2378
2377 myDoc->eolMode = eol; 2379 myDoc->eolMode = eol;
2378 myDoc->setModified(true); 2380 myDoc->setModified(true);
2379} 2381}
2380 2382
2381 2383
2382 2384
2383void KateView::paintEvent(QPaintEvent *e) { 2385void KateView::paintEvent(QPaintEvent *e) {
2384 int x, y; 2386 int x, y;
2385 2387
2386 QRect updateR = e->rect(); // update rectangle 2388 QRect updateR = e->rect(); // update rectangle
2387// debug("Update rect = ( %i, %i, %i, %i )", 2389// debug("Update rect = ( %i, %i, %i, %i )",
2388// updateR.x(),updateR.y(), updateR.width(), updateR.height() ); 2390// updateR.x(),updateR.y(), updateR.width(), updateR.height() );
2389 2391
2390 int ux1 = updateR.x(); 2392 int ux1 = updateR.x();
2391 int uy1 = updateR.y(); 2393 int uy1 = updateR.y();
2392 int ux2 = ux1 + updateR.width(); 2394 int ux2 = ux1 + updateR.width();
2393 int uy2 = uy1 + updateR.height(); 2395 int uy2 = uy1 + updateR.height();
2394 2396
2395 QPainter paint; 2397 QPainter paint;
2396 paint.begin(this); 2398 paint.begin(this);
2397 2399
2398 QColorGroup g = colorGroup(); 2400 QColorGroup g = colorGroup();
2399 x = width(); 2401 x = width();
2400 y = height(); 2402 y = height();
2401 2403
2402 paint.setPen(g.dark()); 2404 paint.setPen(g.dark());
2403 if (uy1 <= 0) paint.drawLine(0,0,x-2,0); 2405 if (uy1 <= 0) paint.drawLine(0,0,x-2,0);
2404 if (ux1 <= 0) paint.drawLine(0,1,0,y-2); 2406 if (ux1 <= 0) paint.drawLine(0,1,0,y-2);
2405 2407
2406 paint.setPen(black); 2408 paint.setPen(black);
2407 if (uy1 <= 1) paint.drawLine(1,1,x-3,1); 2409 if (uy1 <= 1) paint.drawLine(1,1,x-3,1);
2408 if (ux1 <= 1) paint.drawLine(1,2,1,y-3); 2410 if (ux1 <= 1) paint.drawLine(1,2,1,y-3);
2409 2411
2410 paint.setPen(g.midlight()); 2412 paint.setPen(g.midlight());
2411 if (uy2 >= y-1) paint.drawLine(1,y-2,x-3,y-2); 2413 if (uy2 >= y-1) paint.drawLine(1,y-2,x-3,y-2);
2412 if (ux2 >= x-1) paint.drawLine(x-2,1,x-2,y-2); 2414 if (ux2 >= x-1) paint.drawLine(x-2,1,x-2,y-2);
2413 2415
2414 paint.setPen(g.light()); 2416 paint.setPen(g.light());
2415 if (uy2 >= y) paint.drawLine(0,y-1,x-2,y-1); 2417 if (uy2 >= y) paint.drawLine(0,y-1,x-2,y-1);
2416 if (ux2 >= x) paint.drawLine(x-1,0,x-1,y-1); 2418 if (ux2 >= x) paint.drawLine(x-1,0,x-1,y-1);
2417 2419
2418 x -= 2 + 16; 2420 x -= 2 + 16;
2419 y -= 2 + 16; 2421 y -= 2 + 16;
2420 if (ux2 > x && uy2 > y) { 2422 if (ux2 > x && uy2 > y) {
2421 paint.fillRect(x,y,16,16,g.background()); 2423 paint.fillRect(x,y,16,16,g.background());
2422 } 2424 }
2423 paint.end(); 2425 paint.end();
2424} 2426}
2425 2427
2426void KateView::resizeEvent(QResizeEvent *) { 2428void KateView::resizeEvent(QResizeEvent *) {
2427 2429
2428// debug("Resize %d, %d",e->size().width(),e->size().height()); 2430// debug("Resize %d, %d",e->size().width(),e->size().height());
2429 2431
2430//myViewInternal->resize(width() -20, height() -20); 2432//myViewInternal->resize(width() -20, height() -20);
2431 myViewInternal->tagAll(); 2433 myViewInternal->tagAll();
2432 myViewInternal->updateView(0/*ufNoScroll*/); 2434 myViewInternal->updateView(0/*ufNoScroll*/);
2433} 2435}
2434 2436
2435 2437
2436// Applies a new pattern to the search context. 2438// Applies a new pattern to the search context.
2437void SConfig::setPattern(QString &newPattern) { 2439void SConfig::setPattern(QString &newPattern) {
2438 bool regExp = (flags & KateView::sfRegularExpression); 2440 bool regExp = (flags & KateView::sfRegularExpression);
2439 2441
2440 m_pattern = newPattern; 2442 m_pattern = newPattern;
2441 if (regExp) { 2443 if (regExp) {
2442 m_regExp.setCaseSensitive(flags & KateView::sfCaseSensitive); 2444 m_regExp.setCaseSensitive(flags & KateView::sfCaseSensitive);
2443 m_regExp.setPattern(m_pattern); 2445 m_regExp.setPattern(m_pattern);
2444 } 2446 }
2445} 2447}
2446 2448
2447// Applies the search context to the given string, and returns whether a match was found. If one is, 2449// Applies the search context to the given string, and returns whether a match was found. If one is,
2448// the length of the string matched is also returned. 2450// the length of the string matched is also returned.
2449int SConfig::search(QString &text, int index) { 2451int SConfig::search(QString &text, int index) {
2450 bool regExp = (flags & KateView::sfRegularExpression); 2452 bool regExp = (flags & KateView::sfRegularExpression);
2451 bool caseSensitive = (flags & KateView::sfCaseSensitive); 2453 bool caseSensitive = (flags & KateView::sfCaseSensitive);
2452 2454
2453 if (flags & KateView::sfBackward) { 2455 if (flags & KateView::sfBackward) {
2454 if (regExp) { 2456 if (regExp) {
2455 index = text.findRev(m_regExp, index); 2457 index = text.findRev(m_regExp, index);
2456 } 2458 }
2457 else { 2459 else {
2458 index = text.findRev(m_pattern, index, caseSensitive); 2460 index = text.findRev(m_pattern, index, caseSensitive);
2459 } 2461 }
2460 } 2462 }
2461 else { 2463 else {
2462 if (regExp) { 2464 if (regExp) {
2463 index = text.find(m_regExp, index); 2465 index = text.find(m_regExp, index);
2464 } 2466 }
2465 else { 2467 else {
2466 index = text.find(m_pattern, index, caseSensitive); 2468 index = text.find(m_pattern, index, caseSensitive);
2467 } 2469 }
2468 } 2470 }
2469 2471
2470 // Work out the matched length. 2472 // Work out the matched length.
2471 if (index != -1) 2473 if (index != -1)
2472 { 2474 {
2473 if (regExp) { 2475 if (regExp) {
2474 m_regExp.match(text, index, &matchedLength, false); 2476 m_regExp.match(text, index, &matchedLength, false);
2475 } 2477 }
2476 else { 2478 else {
2477 matchedLength = m_pattern.length(); 2479 matchedLength = m_pattern.length();
2478 } 2480 }
2479 } 2481 }
2480 return index; 2482 return index;
2481} 2483}
2482 2484
2483void KateView::setActive (bool b) 2485void KateView::setActive (bool b)
2484{ 2486{
2485 active = b; 2487 active = b;
2486} 2488}
2487 2489
2488bool KateView::isActive () 2490bool KateView::isActive ()
2489{ 2491{
2490 return active; 2492 return active;
2491} 2493}
2492 2494
2493void KateView::setFocus () 2495void KateView::setFocus ()
2494{ 2496{
2495 QWidget::setFocus (); 2497 QWidget::setFocus ();
2496 2498
2497 emit gotFocus (this); 2499 emit gotFocus (this);
2498} 2500}
2499 2501
2500bool KateView::eventFilter (QObject *object, QEvent *event) 2502bool KateView::eventFilter (QObject *object, QEvent *event)
2501{ 2503{
2502 2504
2503 if ( (event->type() == QEvent::FocusIn) ) 2505 if ( (event->type() == QEvent::FocusIn) )
2504 emit gotFocus (this); 2506 emit gotFocus (this);
2505 2507
2506 if ( (event->type() == QEvent::KeyPress) ) 2508 if ( (event->type() == QEvent::KeyPress) )
2507 { 2509 {
2508 QKeyEvent * ke=(QKeyEvent *)event; 2510 QKeyEvent * ke=(QKeyEvent *)event;
2509 2511
2510 if ((ke->key()==Qt::Key_Tab) || (ke->key()==Qt::Key_BackTab)) 2512 if ((ke->key()==Qt::Key_Tab) || (ke->key()==Qt::Key_BackTab))
2511 { 2513 {
2512 myViewInternal->keyPressEvent(ke); 2514 myViewInternal->keyPressEvent(ke);
2513 return true; 2515 return true;
2514 } 2516 }
2515 } 2517 }
2516 return QWidget::eventFilter (object, event); 2518 return QWidget::eventFilter (object, event);
2517} 2519}
2518 2520
2519void KateView::findAgain (bool back) 2521void KateView::findAgain (bool back)
2520{ 2522{
2521 bool b= (searchFlags & sfBackward) > 0; 2523 bool b= (searchFlags & sfBackward) > 0;
2522 initSearch(s, (searchFlags & ((b==back)?~sfBackward:~0) & ~sfFromBeginning) // clear flag for forward searching 2524 initSearch(s, (searchFlags & ((b==back)?~sfBackward:~0) & ~sfFromBeginning) // clear flag for forward searching
2523 | sfPrompt | sfAgain | ((b!=back)?sfBackward:0) ); 2525 | sfPrompt | sfAgain | ((b!=back)?sfBackward:0) );
2524 if (s.flags & sfReplace) 2526 if (s.flags & sfReplace)
2525 replaceAgain(); 2527 replaceAgain();
2526 else 2528 else
2527 KateView::findAgain(s); 2529 KateView::findAgain(s);
2528} 2530}
2529 2531
2530void KateView::slotEditCommand () 2532void KateView::slotEditCommand ()
2531{ 2533{
2532#warning fixme 2534#warning fixme
2533/* 2535/*
2534 bool ok; 2536 bool ok;
2535 QString cmd = KLineEditDlg::getText("Editing Command", "", &ok, this); 2537 QString cmd = KLineEditDlg::getText("Editing Command", "", &ok, this);
2536 2538
2537 if (ok) 2539 if (ok)
2538 myDoc->cmd()->execCmd (cmd, this);*/ 2540 myDoc->cmd()->execCmd (cmd, this);*/
2539} 2541}
2540 2542
2541void KateView::setIconBorder (bool enable) 2543void KateView::setIconBorder (bool enable)
2542{ 2544{
2543 myIconBorder = enable; 2545 myIconBorder = enable;
2544 2546
2545 if (myIconBorder) 2547 if (myIconBorder)
2546 { 2548 {
2547 myViewInternal->move(myViewInternal->iconBorderWidth+2, 2); 2549 myViewInternal->move(myViewInternal->iconBorderWidth+2, 2);
2548 myViewInternal->leftBorder->show(); 2550 myViewInternal->leftBorder->show();
2549 } 2551 }
2550 else 2552 else
2551 { 2553 {
2552 myViewInternal->leftBorder->hide(); 2554 myViewInternal->leftBorder->hide();
2553 myViewInternal->move(2, 2); 2555 myViewInternal->move(2, 2);
2554 } 2556 }
2555} 2557}
2556 2558
2557void KateView::toggleIconBorder () 2559void KateView::toggleIconBorder ()
2558{ 2560{
2559 setIconBorder (!myIconBorder); 2561 setIconBorder (!myIconBorder);
2560} 2562}
2561 2563
2562void KateView::gotoMark (Kate::Mark *mark) 2564void KateView::gotoMark (Kate::Mark *mark)
2563{ 2565{
2564 PointStruc cursor; 2566 PointStruc cursor;
2565 2567
2566 cursor.x = 0; 2568 cursor.x = 0;
2567 cursor.y = mark->line; 2569 cursor.y = mark->line;
2568 myDoc->needPreHighlight(cursor.y); 2570 myDoc->needPreHighlight(cursor.y);
2569 myViewInternal->updateCursor(cursor); 2571 myViewInternal->updateCursor(cursor);
2570 myViewInternal->center(); 2572 myViewInternal->center();
2571 myViewInternal->updateView(KateView::ufUpdateOnScroll); 2573 myViewInternal->updateView(KateView::ufUpdateOnScroll);
2572 myDoc->updateViews(this); 2574 myDoc->updateViews(this);
2573} 2575}
2574 2576
2575void KateView::toggleBookmark () 2577void KateView::toggleBookmark ()
2576{ 2578{
2577 TextLine::Ptr line = myDoc->getTextLine (currentLine()); 2579 TextLine::Ptr line = myDoc->getTextLine (currentLine());
2578 2580
2579 if (line->mark()&KateDocument::Bookmark) 2581 if (line->mark()&KateDocument::Bookmark)
2580 line->delMark(KateDocument::Bookmark); 2582 line->delMark(KateDocument::Bookmark);
2581 else 2583 else
2582 line->addMark(KateDocument::Bookmark); 2584 line->addMark(KateDocument::Bookmark);
2583 2585
2584 myDoc->tagLines (currentLine(), currentLine()); 2586 myDoc->tagLines (currentLine(), currentLine());
2585 myDoc->updateViews(); 2587 myDoc->updateViews();
2586} 2588}
2587 2589
2588void KateView::clearBookmarks() 2590void KateView::clearBookmarks()
2589{ 2591{
2590 QList<Kate::Mark> list = myDoc->marks(); 2592 QList<Kate::Mark> list = myDoc->marks();
2591 for (int i=0; (uint) i < list.count(); i++) 2593 for (int i=0; (uint) i < list.count(); i++)
2592 { 2594 {
2593 if (list.at(i)->type&KateDocument::Bookmark) 2595 if (list.at(i)->type&KateDocument::Bookmark)
2594 { 2596 {
2595 myDoc->getTextLine(list.at(i)->line)->delMark(KateDocument::Bookmark); 2597 myDoc->getTextLine(list.at(i)->line)->delMark(KateDocument::Bookmark);
2596 myDoc->tagLines(list.at(i)->line, list.at(i)->line); 2598 myDoc->tagLines(list.at(i)->line, list.at(i)->line);
2597 } 2599 }
2598 } 2600 }
2599 2601
2600 myDoc->updateViews(); 2602 myDoc->updateViews();
2601} 2603}
2602 2604
2603void KateView::bookmarkMenuAboutToShow() 2605void KateView::bookmarkMenuAboutToShow()
2604{ 2606{
2605#warning fixme 2607#warning fixme
2606#if 0 2608#if 0
2607 bookmarkMenu->popupMenu()->clear (); 2609 bookmarkMenu->popupMenu()->clear ();
2608 bookmarkToggle->plug (bookmarkMenu->popupMenu()); 2610 bookmarkToggle->plug (bookmarkMenu->popupMenu());
2609 bookmarkClear->plug (bookmarkMenu->popupMenu()); 2611 bookmarkClear->plug (bookmarkMenu->popupMenu());
2610 bookmarkMenu->popupMenu()->insertSeparator (); 2612 bookmarkMenu->popupMenu()->insertSeparator ();
2611 2613
2612 list = myDoc->marks(); 2614 list = myDoc->marks();
2613 for (int i=0; (uint) i < list.count(); i++) 2615 for (int i=0; (uint) i < list.count(); i++)
2614 { 2616 {
2615 if (list.at(i)->type&KateDocument::Bookmark) 2617 if (list.at(i)->type&KateDocument::Bookmark)
2616 { 2618 {
2617 QString bText = textLine(list.at(i)->line); 2619 QString bText = textLine(list.at(i)->line);
2618 bText.truncate(32); 2620 bText.truncate(32);
2619 bText.append ("..."); 2621 bText.append ("...");
2620 bookmarkMenu->popupMenu()->insertItem ( QString("%1 - \"%2\"").arg(list.at(i)->line).arg(bText), this, SLOT (gotoBookmark(int)), 0, i ); 2622 bookmarkMenu->popupMenu()->insertItem ( QString("%1 - \"%2\"").arg(list.at(i)->line).arg(bText), this, SLOT (gotoBookmark(int)), 0, i );
2621 } 2623 }
2622 } 2624 }
2623#endif 2625#endif
2624} 2626}
2625 2627
2626void KateView::gotoBookmark (int n) 2628void KateView::gotoBookmark (int n)
2627{ 2629{
2628 gotoMark (list.at(n)); 2630 gotoMark (list.at(n));
2629} 2631}
2630 2632
2631int KateView::getHlCount () 2633int KateView::getHlCount ()
2632{ 2634{
2633 return HlManager::self()->highlights(); 2635 return HlManager::self()->highlights();
2634} 2636}
2635 2637
2636QString KateView::getHlName (int z) 2638QString KateView::getHlName (int z)
2637{ 2639{
2638 return HlManager::self()->hlName(z); 2640 return HlManager::self()->hlName(z);
2639} 2641}
2640 2642
2641QString KateView::getHlSection (int z) 2643QString KateView::getHlSection (int z)
2642{ 2644{
2643 return HlManager::self()->hlSection (z); 2645 return HlManager::self()->hlSection (z);
2644} 2646}
2645 2647
2646void KateView::slotIncFontSizes () 2648void KateView::slotIncFontSizes ()
2647{ 2649{
2648 QFont font = myDoc->getFont(); 2650 QFont font = myDoc->getFont();
2649 font.setPointSize (font.pointSize()+2); 2651 font.setPointSize (font.pointSize()+2);
2650 myDoc->setFont (font); 2652 myDoc->setFont (font);
2651} 2653}
2652 2654
2653void KateView::slotDecFontSizes () 2655void KateView::slotDecFontSizes ()
2654{ 2656{
2655 QFont font = myDoc->getFont(); 2657 QFont font = myDoc->getFont();
2656 font.setPointSize (font.pointSize()-2); 2658 font.setPointSize (font.pointSize()-2);
2657 myDoc->setFont (font); 2659 myDoc->setFont (font);
2658} 2660}
2659 2661
2660const char*bookmark_xpm[]={ 2662const char*bookmark_xpm[]={
2661"12 16 4 1", 2663"12 16 4 1",
2662"b c #808080", 2664"b c #808080",
2663"a c #000080", 2665"a c #000080",
2664"# c #0000ff", 2666"# c #0000ff",
2665". c None", 2667". c None",
2666"............", 2668"............",
2667"............", 2669"............",
2668"........###.", 2670"........###.",
2669".......#...a", 2671".......#...a",
2670"......#.##.a", 2672"......#.##.a",
2671".....#.#..aa", 2673".....#.#..aa",
2672"....#.#...a.", 2674"....#.#...a.",
2673"...#.#.a.a..", 2675"...#.#.a.a..",
2674"..#.#.a.a...", 2676"..#.#.a.a...",
2675".#.#.a.a....", 2677".#.#.a.a....",
2676"#.#.a.a.....", 2678"#.#.a.a.....",
2677"#.#a.a...bbb", 2679"#.#a.a...bbb",
2678"#...a..bbb..", 2680"#...a..bbb..",
2679".aaa.bbb....", 2681".aaa.bbb....",
2680"............", 2682"............",
2681"............"}; 2683"............"};
2682 2684
2683const char* breakpoint_xpm[]={ 2685const char* breakpoint_xpm[]={
2684"11 16 6 1", 2686"11 16 6 1",
2685"c c #c6c6c6", 2687"c c #c6c6c6",
2686". c None", 2688". c None",
2687"# c #000000", 2689"# c #000000",
2688"d c #840000", 2690"d c #840000",
2689"a c #ffffff", 2691"a c #ffffff",
2690"b c #ff0000", 2692"b c #ff0000",
2691"...........", 2693"...........",
2692"...........", 2694"...........",
2693"...#####...", 2695"...#####...",
2694"..#aaaaa#..", 2696"..#aaaaa#..",
2695".#abbbbbb#.", 2697".#abbbbbb#.",
2696"#abbbbbbbb#", 2698"#abbbbbbbb#",
2697"#abcacacbd#", 2699"#abcacacbd#",
2698"#abbbbbbbb#", 2700"#abbbbbbbb#",
2699"#abcacacbd#", 2701"#abcacacbd#",
2700"#abbbbbbbb#", 2702"#abbbbbbbb#",
2701".#bbbbbbb#.", 2703".#bbbbbbb#.",
2702"..#bdbdb#..", 2704"..#bdbdb#..",
2703"...#####...", 2705"...#####...",
2704"...........", 2706"...........",
2705"...........", 2707"...........",
2706"..........."}; 2708"..........."};
2707 2709
2708const char*breakpoint_bl_xpm[]={ 2710const char*breakpoint_bl_xpm[]={
2709"11 16 7 1", 2711"11 16 7 1",
2710"a c #c0c0ff", 2712"a c #c0c0ff",
2711"# c #000000", 2713"# c #000000",
2712"c c #0000c0", 2714"c c #0000c0",
2713"e c #0000ff", 2715"e c #0000ff",
2714"b c #dcdcdc", 2716"b c #dcdcdc",
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp
index ea7ea45..dda8405 100644
--- a/noncore/apps/tinykate/tinykate.cpp
+++ b/noncore/apps/tinykate/tinykate.cpp
@@ -1,276 +1,321 @@
1/*************************************************************************** 1/***************************************************************************
2 tinykate.cpp 2 tinykate.cpp
3 Tiny KATE mainwindow 3 Tiny KATE mainwindow
4 ------------------- 4 -------------------
5 begin : November 2002 5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> 6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free softwaSre; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. * 13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * 14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17#include <qwidget.h> 17#include <qwidget.h>
18#include <qaction.h> 18#include <qaction.h>
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qtoolbutton.h> 20#include <qpe/qpetoolbar.h>
21#include <qmenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25 25
26#include <opie/ofiledialog.h> 26#include <opie/ofiledialog.h>
27 27
28#include "cgotoline.h"
29
28#include "tinykate.h" 30#include "tinykate.h"
29 31
30#include <katedocument.h> 32#include <katedocument.h>
31#include <katehighlight.h> 33#include <katehighlight.h>
32#include <kateview.h> 34#include <kateview.h>
33#include <kglobal.h> 35#include <kglobal.h>
34 36
35TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : 37TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
36 QMainWindow( parent, name, f ) 38 QMainWindow( parent, name, f )
37{ 39{
38 nextUnnamed=0; 40 nextUnnamed=0;
39 currentView=0; 41 currentView=0;
40 viewCount=0; 42 viewCount=0;
41 setCaption(tr("TinyKATE")); 43 setCaption("TinyKATE : line 1 col 1");
42 KGlobal::setAppName("TinyKATE"); 44 KGlobal::setAppName("TinyKATE");
43 45
44 QMenuBar *mb = new QMenuBar( this ); 46 curLine=curCol=1;
45 mb->setMargin( 0 ); 47
48 setToolBarsMovable(FALSE);
49
50 QPEToolBar *bar = new QPEToolBar( this );
51 bar->setHorizontalStretchable( TRUE );
52 QPEMenuBar *mb = new QPEMenuBar( bar );
53 mb->setMargin( 0 );
46 54
47 tabwidget=new OTabWidget(this); 55 tabwidget=new OTabWidget(this);
48 setCentralWidget(tabwidget); 56 setCentralWidget(tabwidget);
49 connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); 57 connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *)));
50 58
51//FILE ACTIONS 59//FILE ACTIONS
52 QPopupMenu *popup = new QPopupMenu( this ); 60 QPopupMenu *popup = new QPopupMenu( this );
53 61
54 // Action for creating a new document 62 // Action for creating a new document
55 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 63 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, CTRL+Key_N, this, 0 );
56 a->addTo( popup ); 64 a->addTo( popup );
57 connect(a, SIGNAL(activated()), this, SLOT(slotNew())); 65 connect(a, SIGNAL(activated()), this, SLOT(slotNew()));
58 66
59 // Action for opening an exisiting document 67 // Action for opening an exisiting document
60 a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 ); 68 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, CTRL+Key_O, this, 0 );
61 a->addTo(popup); 69 a->addTo(popup);
62 connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); 70 connect(a, SIGNAL(activated()), this, SLOT(slotOpen()));
63 71
64 72
65 // Action for saving document 73 // Action for saving document
66 a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); 74 a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ), QString::null, CTRL+Key_S, this, 0 );
67 a->addTo(popup); 75 a->addTo(popup);
68 connect(a, SIGNAL(activated()), this, SLOT(slotSave())); 76 connect(a, SIGNAL(activated()), this, SLOT(slotSave()));
69 77
70 // Action for saving document to a new name 78 // Action for saving document to a new name
71 a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); 79 a = new QAction( tr( "Save As" ), Resource::loadPixmap( "save" ), QString::null, 0, this, 0 );
72 a->addTo(popup); 80 a->addTo(popup);
73 connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); 81 connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs()));
74 82
75 // Action for closing the currently active document 83 // Action for closing the currently active document
76 a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 ); 84 a = new QAction( tr( "Close" ), Resource::loadPixmap( "close" ), QString::null, CTRL+Key_W, this, 0 );
77 a->addTo(popup); 85 a->addTo(popup);
78 connect(a, SIGNAL(activated()), this, SLOT(slotClose())); 86 connect(a, SIGNAL(activated()), this, SLOT(slotClose()));
79 87
80 88
81 mb->insertItem(tr("File"),popup); 89 mb->insertItem(tr("File"),popup);
82 90
83//EDIT ACTIONS 91//EDIT ACTIONS
84 92
85 // Action for cutting text 93 // Action for cutting text
86 editCut = new QToolButton( 0 ); 94 editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, CTRL+Key_X, this, 0 );
87 editCut->setAutoRaise( true ); 95 editCut->addTo( bar );
88 editCut->setIconSet( Resource::loadPixmap( "cut" ) );
89 96
90 // Action for Copying text 97 // Action for Copying text
91 editCopy = new QToolButton( 0 ); 98 editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, CTRL+Key_C, this, 0 );
92 editCopy->setAutoRaise( true ); 99 editCopy->addTo( bar );
93 editCopy->setIconSet( Resource::loadPixmap( "copy" ) );
94 100
95 // Action for pasting text 101 // Action for pasting text
96 editPaste = new QToolButton( 0 ); 102 editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, CTRL+Key_V, this, 0 );
97 editPaste->setAutoRaise( true ); 103 editPaste->addTo( bar );
98 editPaste->setIconSet( Resource::loadPixmap( "paste" ) ); 104
99 105
100 // Action for finding / replacing text 106 // Action for finding / replacing text
101 editFindReplace = new QToolButton( 0 ); 107 editFindReplace = new QAction( tr( "Replace" ), Resource::loadPixmap("find"), QString::null, CTRL+Key_R, this, 0 );
102 editFindReplace->setAutoRaise( true ); 108 editFind = new QAction( tr( "Find" ), Resource::loadPixmap("find"), QString::null, CTRL+Key_F, this, 0 );
103 editFindReplace->setIconSet( Resource::loadPixmap("find") ); 109 editFind->addTo( bar );
104 110
105 // Action for undo 111 // Action for undo
106 editUndo = new QToolButton( 0 ); 112 editUndo = new QAction( tr( "Undo" ), Resource::loadPixmap( "undo" ), QString::null, CTRL+Key_Z, this, 0 );
107 editUndo->setAutoRaise( true ); 113 editUndo->addTo( bar );
108 editUndo->setIconSet( Resource::loadPixmap( "undo" ) );
109 114
110 // Action for redo 115 // Action for redo
111 editRedo = new QToolButton( 0 ); 116 editRedo = new QAction( tr( "Redo" ), Resource::loadPixmap( "redo" ), QString::null, CTRL+SHIFT+Key_Z, this, 0 );
112 editRedo->setAutoRaise( true ); 117 editRedo->addTo( bar );
113 editRedo->setIconSet( Resource::loadPixmap( "redo" ) ); 118
114 119
115//VIEW ACITONS 120//VIEW ACITONS
116 popup = new QPopupMenu( this ); 121 popup = new QPopupMenu( this );
117 122
123 a = new QAction( tr( "Goto" ), QString::null, CTRL+Key_G, this, 0 );
124 a->addTo( popup );
125 connect(a, SIGNAL(activated()), this, SLOT(slotGoTo()));
126
118 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); 127 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 );
119 viewIncFontSizes->addTo( popup ); 128 viewIncFontSizes->addTo( popup );
120 129
121 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); 130 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 );
122 viewDecFontSizes->addTo( popup ); 131 viewDecFontSizes->addTo( popup );
123 132
124 mb->insertItem(tr("View"),popup); 133 mb->insertItem(tr("View"),popup);
125
126 popup = new QPopupMenu( this );
127 mb->insertItem(tr("Utils"),popup);
128 134
129 135
130 mb->insertItem( editCut );
131 mb->insertItem( editCopy );
132 mb->insertItem( editPaste );
133 mb->insertItem( editFindReplace );
134 mb->insertItem( editUndo );
135 mb->insertItem( editRedo );
136 136
137 popup = new QPopupMenu( this );
138 mb->insertItem(tr("Utils"),popup);
137 139
138//Highlight management 140//Highlight management
139 hlmenu=new QPopupMenu(this); 141 hlmenu=new QPopupMenu(this);
140 HlManager *hlm=HlManager::self(); 142 HlManager *hlm=HlManager::self();
141 for (int i=0;i<hlm->highlights();i++) 143 for (int i=0;i<hlm->highlights();i++)
142 { 144 {
143 hlmenu->insertItem(hlm->hlName(i),i); 145 hlmenu->insertItem(hlm->hlName(i),i);
144 } 146 }
145 popup->insertItem(tr("Highlighting"),hlmenu); 147 popup->insertItem(tr("Highlighting"),hlmenu);
146 148
147 149
148 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); 150 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 );
149 utilSettings->addTo( popup); 151 utilSettings->addTo( popup);
150 152
153 popup->insertSeparator();
154 editFind->addTo(popup);
155 editFindReplace->addTo(popup);
156
151 if( qApp->argc() > 1) open(qApp->argv()[1]); 157 if( qApp->argc() > 1) open(qApp->argv()[1]);
152 else slotNew(); 158 else slotNew();
153 159
154} 160}
155 161
156TinyKate::~TinyKate( ) 162TinyKate::~TinyKate( )
157{ 163{
158 qWarning("TinyKate destructor\n"); 164 qWarning("TinyKate destructor\n");
165 printf("~TinyKate()\n");
159 if( KGlobal::config() != 0 ) { 166 if( KGlobal::config() != 0 ) {
167 printf("~TinyKate(): delete configs...\n");
160 qWarning("deleting KateConfig object..\n"); 168 qWarning("deleting KateConfig object..\n");
161 delete KGlobal::config(); 169 delete KGlobal::config();
162 } 170 }
163} 171}
164 172
165void TinyKate::slotOpen( ) 173void TinyKate::slotOpen( )
166{ 174{
167 QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 175 QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
168 QPEApplication::documentDir()); 176 QString::null);
169 if (!filename.isEmpty()) { 177 if (!filename.isEmpty()) {
170 open(filename); 178 open(filename);
171 } 179 }
172} 180}
173 181
174void TinyKate::open(const QString & filename) 182void TinyKate::open(const QString & filename)
175{ 183{
176 KateDocument *kd= new KateDocument(false, false, this,0,this); 184 KateDocument *kd= new KateDocument(false, false, this,0,this);
177 KTextEditor::View *kv; 185 KTextEditor::View *kv;
178 QFileInfo fi(filename); 186 QFileInfo fi(filename);
179 QString filenamed = fi.fileName(); 187 QString filenamed = fi.fileName();
180 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); 188 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed );
181 qDebug(filename); 189 qDebug(filename);
182 190
183 kd->setDocName( filenamed); 191 kd->setDocName( filenamed);
184 kd->open( filename ); 192 kd->open( filename );
185 viewCount++; 193 viewCount++;
186} 194}
187 195
188void TinyKate::setDocument(const QString& fileref) 196void TinyKate::setDocument(const QString &doc)
189{ 197{
190 open( fileref ); 198 printf("tinykate: setDocument(\"%s\")\n",(const char*)doc);
199 open(doc);
191} 200}
192 201
193void TinyKate::slotCurrentChanged( QWidget * view) 202void TinyKate::slotCurrentChanged( QWidget * view)
194{ 203{
195 if (currentView) { 204 if (currentView) {
196 205
197 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); 206 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
198 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); 207 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
199 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); 208 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
200 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); 209 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
201 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); 210 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
202 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 211 disconnect(editFindReplace,SIGNAL(activated()),currentView,SLOT(replace()));
203 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 212 disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find()));
213 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
214 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
204 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 215 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
205 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 216 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
217 disconnect(currentView,SIGNAL(newCurPos()),this,SLOT(slotCursorMoved()));
206 } 218 }
207 219
208 currentView=(KTextEditor::View*)view; 220 currentView=(KTextEditor::View*)view;
209 221
210 connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); 222 connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
211 connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); 223 connect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
212 connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); 224 connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
213 connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); 225 connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
214 connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); 226 connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
227 connect(editFindReplace,SIGNAL(activated()),currentView,SLOT(replace()));
228 connect(editFind,SIGNAL(activated()),currentView,SLOT(find()));
215 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 229 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
216 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 230 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
217 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 231 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
218 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 232 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
219 233 connect(currentView,SIGNAL(newCurPos()),this,SLOT(slotCursorMoved()));
220} 234}
221 235
222void TinyKate::slotNew( ) 236void TinyKate::slotNew( )
223{ 237{
224 KateDocument *kd= new KateDocument(false, false, this,0,this); 238 KateDocument *kd= new KateDocument(false, false, this,0,this);
225 KTextEditor::View *kv; 239 KTextEditor::View *kv;
226 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), 240 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),
227 "tinykate/tinykate", 241 "tinykate/tinykate",
228 tr("Unnamed %1").arg(nextUnnamed++)); 242 tr("Unnamed %1").arg(nextUnnamed++));
229 viewCount++; 243 viewCount++;
230} 244}
231 245
232void TinyKate::slotClose( ) 246void TinyKate::slotClose( )
233{ 247{
234 if (currentView==0) return; 248 if (currentView==0) return;
235 KTextEditor::View *dv=currentView; 249 KTextEditor::View *dv=currentView;
236 currentView=0; 250 currentView=0;
237 tabwidget->removePage(dv); 251 tabwidget->removePage(dv);
238 delete dv->document(); 252 delete dv->document();
239 viewCount--; 253 viewCount--;
240 if (!viewCount) slotNew(); 254 if (!viewCount) slotNew();
241} 255}
242 256
243void TinyKate::slotSave() { 257void TinyKate::slotSave() {
244 // feel free to make this how you want 258 // feel free to make this how you want
245 if (currentView==0) return; 259 if (currentView==0) return;
246 260
247 // KateView *kv = (KateView*) currentView; 261 // KateView *kv = (KateView*) currentView;
248 KateDocument *kd = (KateDocument*) currentView->document(); 262 KateDocument *kd = (KateDocument*) currentView->document();
249 // qDebug("saving file "+kd->docName()); 263 // qDebug("saving file "+kd->docName());
250 if( kd->docName().isEmpty()) 264 if( kd->docName().isEmpty())
251 slotSaveAs(); 265 slotSaveAs();
252 else 266 else
253 kd->saveFile(); 267 kd->saveFile();
254 // kv->save(); 268 // kv->save();
255 // kd->saveFile(); 269 // kd->saveFile();
256} 270}
257 271
258void TinyKate::slotSaveAs() { 272void TinyKate::slotSaveAs() {
259 if (currentView==0) return; 273 if (currentView==0) return;
260 KateDocument *kd = (KateDocument*) currentView->document(); 274 KateDocument *kd = (KateDocument*) currentView->document();
261 275
262 QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, 276 QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL,
263 QPEApplication::documentDir()); 277 QString::null);
264 if (!filename.isEmpty()) { 278 if (!filename.isEmpty()) {
265 qDebug("saving file "+filename); 279 qDebug("saving file "+filename);
266 QFileInfo fi(filename); 280 QFileInfo fi(filename);
267 QString filenamed = fi.fileName(); 281 QString filenamed = fi.fileName();
268 kd->setDocFile( filename); 282 kd->setDocFile( filename);
269 kd->setDocName( filenamed); 283 kd->setDocName( filenamed);
270 kd->saveFile(); 284 kd->saveFile();
271// KTextEditor::View *dv = currentView; 285// KTextEditor::View *dv = currentView;
272// tabwidget->changeTab( dv, filenamed); 286// tabwidget->changeTab( dv, filenamed);
273 // need to change tab label here 287 // need to change tab label here
274 } 288 }
275 289
276} 290}
291
292void TinyKate::slotGoTo()
293{
294 int l,c;
295 if (currentView==0) return;
296
297 currentView->getCursorPosition(&l,&c);
298
299 CGotoLine g(l);
300
301 if(g.exec()==QDialog::Accepted)
302 {
303 currentView->setCursorPosition( g.line(), c );
304 }
305}
306
307void TinyKate::slotCursorMoved()
308{
309 char buf[100];
310 int newLine,newCol;
311 currentView->getCursorPosition(&newLine,&newCol);
312 newLine++;
313 newCol++;
314 if((newLine!=curLine)||(newCol!=curCol))
315 {
316 sprintf(buf,"TinyKATE : line %-6d col %d",newLine,newCol);
317 setCaption(buf);
318 curLine=newLine;
319 curCol=newCol;
320 }
321}
diff --git a/noncore/apps/tinykate/tinykate.h b/noncore/apps/tinykate/tinykate.h
index 2e8ca74..077d5f0 100644
--- a/noncore/apps/tinykate/tinykate.h
+++ b/noncore/apps/tinykate/tinykate.h
@@ -1,63 +1,75 @@
1/*************************************************************************** 1/***************************************************************************
2 tinykate.h 2 tinykate.h
3 Tiny KATE mainwindow 3 Tiny KATE mainwindow
4 ------------------- 4 -------------------
5 begin : November 2002 5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> 6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. * 13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * 14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#ifndef __TINYKATE_H__ 18#ifndef __TINYKATE_H__
19#define __TINYKATE_H__ 19#define __TINYKATE_H__
20 20
21 21
22#include <qmainwindow.h> 22#include <qmainwindow.h>
23#include <opie/otabwidget.h> 23#include <opie/otabwidget.h>
24#include <ktexteditor.h> 24#include <ktexteditor.h>
25 25
26class QToolButton;
27class QAction; 26class QAction;
28class QPopupMenu; 27class QPopupMenu;
28class CGotoLine;
29 29
30class TinyKate : public QMainWindow 30class TinyKate : public QMainWindow
31{ 31{
32Q_OBJECT 32Q_OBJECT
33public: 33public:
34 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); 34 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0);
35 ~TinyKate( ); 35 ~TinyKate( );
36 36
37public slots: 37public slots:
38 void slotNew(); 38 void slotNew();
39 void setDocument(const QString& fileref);
40 39
41protected slots: 40protected slots:
42 void slotOpen(); 41 void slotOpen();
43 void slotClose(); 42 void slotClose();
44 void slotCurrentChanged(QWidget *); 43 void slotCurrentChanged(QWidget *);
45 void slotSave(); 44 void slotSave();
46 void slotSaveAs(); 45 void slotSaveAs();
46 void slotGoTo();
47 void slotCursorMoved();
48 void setDocument(const QString &doc);
49
47protected: 50protected:
48 void open(const QString&); 51 void open(const QString&);
49private: 52private:
50 QString currentFileName; 53 QString currentFileName;
51 OTabWidget *tabwidget; 54 OTabWidget *tabwidget;
52 KTextEditor::View *currentView; 55 KTextEditor::View *currentView;
53 56
54 QToolButton *editCopy, *editCut, *editPaste, *editUndo, *editRedo, *editFindReplace; 57 QAction *editCopy;
55 QAction *viewIncFontSizes, *viewDecFontSizes, *utilSettings; 58 QAction *editCut;
56 59 QAction *editPaste;
60 QAction *editUndo;
61 QAction *editRedo;
62 QAction *editFind;
63 QAction *editFindReplace;
64 QAction *viewIncFontSizes;
65 QAction *viewDecFontSizes;
66 QAction *utilSettings;
67
57 QPopupMenu *hlmenu; 68 QPopupMenu *hlmenu;
58 uint nextUnnamed; 69 uint nextUnnamed;
59 uint viewCount; 70 uint viewCount;
71 int curLine,curCol;
60}; 72};
61 73
62 74
63#endif // __TINYKATE_H__ 75#endif // __TINYKATE_H__
diff --git a/noncore/apps/tinykate/tinykate.pro b/noncore/apps/tinykate/tinykate.pro
index 632bd49..f7ff451 100644
--- a/noncore/apps/tinykate/tinykate.pro
+++ b/noncore/apps/tinykate/tinykate.pro
@@ -1,22 +1,22 @@
1 TEMPLATE= app 1TEMPLATE = app
2 CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3DESTDIR = $(OPIEDIR)/bin
4 HEADERS = tinykate.h 4HEADERS = tinykate.h cgotoline.h
5 SOURCES = tinykate.cpp main.cpp 5SOURCES = tinykate.cpp main.cpp cgotoline.cpp
6 INTERFACES= 6INTERFACES = cgotobase.ui
7 INCLUDEPATH+= $(OPIEDIR)/include \ 7INCLUDEPATH += $(OPIEDIR)/include \
8 $(OPIEDIR)/noncore/apps/tinykate/libkate \ 8 $(OPIEDIR)/noncore/apps/tinykate/libkate \
9 $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ 9 $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \
10 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ 10 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \
11 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ 11 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \
12 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ 12 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \
13 $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \ 13 $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \
14 $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back 14 $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back
15 15
16 DEPENDPATH+= $(OPIEDIR)/include 16DEPENDPATH += $(OPIEDIR)/include
17LIBS += -lqpe -ltinykate -lopie 17LIBS += -lqpe -ltinykate -lopie
18 TARGET = tinykate 18TARGET = tinykate
19 19
20 20
21 21
22include ( $(OPIEDIR)/include.pro ) 22include ( $(OPIEDIR)/include.pro )