• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
kateviewhelpers.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
3 Copyright (C) 2001 Anders Lund <anders@alweb.dk>
4 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "kateviewhelpers.h"
22#include "kateviewhelpers.moc"
23
24#include "../interfaces/document.h"
25#include "../interfaces/katecmd.h"
26#include "kateattribute.h"
27#include "katecodefoldinghelpers.h"
28#include "kateconfig.h"
29#include "katedocument.h"
30#include "katefactory.h"
31#include "katerenderer.h"
32#include "kateview.h"
33#include "kateviewinternal.h"
34
35#include <tdeapplication.h>
36#include <tdeglobalsettings.h>
37#include <tdelocale.h>
38#include <knotifyclient.h>
39#include <tdeglobal.h>
40#include <kcharsets.h>
41#include <tdepopupmenu.h>
42
43#include <tqcursor.h>
44#include <tqpainter.h>
45#include <tqpopupmenu.h>
46#include <tqstyle.h>
47#include <tqtimer.h>
48#include <tqwhatsthis.h>
49#include <tqregexp.h>
50#include <tqtextcodec.h>
51
52#include <math.h>
53
54#include <kdebug.h>
55
56//BEGIN KateScrollBar
57KateScrollBar::KateScrollBar (Orientation orientation, KateViewInternal* parent, const char* name)
58 : TQScrollBar (orientation, parent->m_view, name)
59 , m_middleMouseDown (false)
60 , m_view(parent->m_view)
61 , m_doc(parent->m_doc)
62 , m_viewInternal(parent)
63 , m_topMargin(-1)
64 , m_bottomMargin(-1)
65 , m_savVisibleLines(0)
66 , m_showMarks(false)
67{
68 connect(this, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(sliderMaybeMoved(int)));
69 connect(m_doc, TQ_SIGNAL(marksChanged()), this, TQ_SLOT(marksChanged()));
70
71 m_lines.setAutoDelete(true);
72}
73
74void KateScrollBar::mousePressEvent(TQMouseEvent* e)
75{
76 if (e->button() == TQt::MidButton)
77 m_middleMouseDown = true;
78
79 TQScrollBar::mousePressEvent(e);
80
81 redrawMarks();
82}
83
84void KateScrollBar::mouseReleaseEvent(TQMouseEvent* e)
85{
86 TQScrollBar::mouseReleaseEvent(e);
87
88 m_middleMouseDown = false;
89
90 redrawMarks();
91}
92
93void KateScrollBar::mouseMoveEvent(TQMouseEvent* e)
94{
95 TQScrollBar::mouseMoveEvent(e);
96
97 if (e->state() | TQt::LeftButton)
98 redrawMarks();
99}
100
101void KateScrollBar::paintEvent(TQPaintEvent *e)
102{
103 TQScrollBar::paintEvent(e);
104 redrawMarks();
105}
106
107void KateScrollBar::resizeEvent(TQResizeEvent *e)
108{
109 TQScrollBar::resizeEvent(e);
110 recomputeMarksPositions();
111}
112
113void KateScrollBar::styleChange(TQStyle &s)
114{
115 TQScrollBar::styleChange(s);
116 m_topMargin = -1;
117 recomputeMarksPositions();
118}
119
120void KateScrollBar::valueChange()
121{
122 TQScrollBar::valueChange();
123 redrawMarks();
124}
125
126void KateScrollBar::rangeChange()
127{
128 TQScrollBar::rangeChange();
129 recomputeMarksPositions();
130}
131
132void KateScrollBar::marksChanged()
133{
134 recomputeMarksPositions(true);
135}
136
137void KateScrollBar::redrawMarks()
138{
139 if (!m_showMarks)
140 return;
141
142 TQPainter painter(this);
143 TQRect rect = sliderRect();
144 for (TQIntDictIterator<TQColor> it(m_lines); it.current(); ++it)
145 {
146 if (it.currentKey() < rect.top() || it.currentKey() > rect.bottom())
147 {
148 painter.setPen(*it.current());
149 painter.drawLine(0, it.currentKey(), width(), it.currentKey());
150 }
151 }
152}
153
154void KateScrollBar::recomputeMarksPositions(bool forceFullUpdate)
155{
156 if (m_topMargin == -1)
157 watchScrollBarSize();
158
159 m_lines.clear();
160 m_savVisibleLines = m_doc->visibleLines();
161
162 int realHeight = frameGeometry().height() - m_topMargin - m_bottomMargin;
163
164 TQPtrList<KTextEditor::Mark> marks = m_doc->marks();
165 KateCodeFoldingTree *tree = m_doc->foldingTree();
166
167 for (KTextEditor::Mark *mark = marks.first(); mark; mark = marks.next())
168 {
169 uint line = mark->line;
170
171 if (tree)
172 {
173 KateCodeFoldingNode *node = tree->findNodeForLine(line);
174
175 while (node)
176 {
177 if (!node->isVisible())
178 line = tree->getStartLine(node);
179 node = node->getParentNode();
180 }
181 }
182
183 line = m_doc->getVirtualLine(line);
184
185 double d = (double)line / (m_savVisibleLines - 1);
186 m_lines.insert(m_topMargin + (int)(d * realHeight),
187 new TQColor(KateRendererConfig::global()->lineMarkerColor((KTextEditor::MarkInterface::MarkTypes)mark->type)));
188 }
189
190 if (forceFullUpdate)
191 update();
192 else
193 redrawMarks();
194}
195
196void KateScrollBar::watchScrollBarSize()
197{
198 int savMax = maxValue();
199 setMaxValue(0);
200 TQRect rect = sliderRect();
201 setMaxValue(savMax);
202
203 m_topMargin = rect.top();
204 m_bottomMargin = frameGeometry().height() - rect.bottom();
205}
206
207void KateScrollBar::sliderMaybeMoved(int value)
208{
209 if (m_middleMouseDown)
210 emit sliderMMBMoved(value);
211}
212//END
213
214//BEGIN KateCmdLnWhatsThis
215class KateCmdLnWhatsThis : public TQWhatsThis
216{
217 public:
218 KateCmdLnWhatsThis( KateCmdLine *parent )
219 : TQWhatsThis( parent )
220 , m_parent( parent ) {;}
221
222 TQString text( const TQPoint & )
223 {
224 TQString beg = "<qt background=\"white\"><div><table width=\"100%\"><tr><td bgcolor=\"brown\"><font color=\"white\"><b>Help: <big>";
225 TQString mid = "</big></b></font></td></tr><tr><td>";
226 TQString end = "</td></tr></table></div><qt>";
227
228 TQString t = m_parent->text();
229 TQRegExp re( "\\s*help\\s+(.*)" );
230 if ( re.search( t ) > -1 )
231 {
232 TQString s;
233 // get help for command
234 TQString name = re.cap( 1 );
235 if ( name == "list" )
236 {
237 return beg + i18n("Available Commands") + mid
238 + KateCmd::self()->cmds().join(" ")
239 + i18n("<p>For help on individual commands, do <code>'help &lt;command&gt;'</code></p>")
240 + end;
241 }
242 else if ( ! name.isEmpty() )
243 {
244 Kate::Command *cmd = KateCmd::self()->queryCommand( name );
245 if ( cmd )
246 {
247 if ( cmd->help( (Kate::View*)m_parent->parentWidget(), name, s ) )
248 return beg + name + mid + s + end;
249 else
250 return beg + name + mid + i18n("No help for '%1'").arg( name ) + end;
251 }
252 else
253 return beg + mid + i18n("No such command <b>%1</b>").arg(name) + end;
254 }
255 }
256
257 return beg + mid + i18n(
258 "<p>This is the Katepart <b>command line</b>.<br>"
259 "Syntax: <code><b>command [ arguments ]</b></code><br>"
260 "For a list of available commands, enter <code><b>help list</b></code><br>"
261 "For help for individual commands, enter <code><b>help &lt;command&gt;</b></code></p>")
262 + end;
263 }
264
265 private:
266 KateCmdLine *m_parent;
267};
268//END KateCmdLnWhatsThis
269
270//BEGIN KateCmdLineFlagCompletion
275class KateCmdLineFlagCompletion : public TDECompletion
276{
277 public:
278 KateCmdLineFlagCompletion() {;}
279
280 TQString makeCompletion( const TQString & string )
281 {
282 return TQString::null;
283 }
284
285};
286//END KateCmdLineFlagCompletion
287
288//BEGIN KateCmdLine
289KateCmdLine::KateCmdLine (KateView *view)
290 : KLineEdit (view)
291 , m_view (view)
292 , m_msgMode (false)
293 , m_histpos( 0 )
294 , m_cmdend( 0 )
295 , m_command( 0L )
296 , m_oldCompletionObject( 0L )
297{
298 connect (this, TQ_SIGNAL(returnPressed(const TQString &)),
299 this, TQ_SLOT(slotReturnPressed(const TQString &)));
300
301 completionObject()->insertItems (KateCmd::self()->cmds());
302 setAutoDeleteCompletionObject( false );
303 m_help = new KateCmdLnWhatsThis( this );
304}
305
306void KateCmdLine::slotReturnPressed ( const TQString& text )
307{
308
309 // silently ignore leading space
310 uint n = 0;
311 while( text[n].isSpace() )
312 n++;
313
314 TQString cmd = text.mid( n );
315
316 // Built in help: if the command starts with "help", [try to] show some help
317 if ( cmd.startsWith( "help" ) )
318 {
319 m_help->display( m_help->text( TQPoint() ), mapToGlobal(TQPoint(0,0)) );
320 clear();
321 KateCmd::self()->appendHistory( cmd );
322 m_histpos = KateCmd::self()->historyLength();
323 m_oldText = TQString ();
324 return;
325 }
326
327 if (cmd.length () > 0)
328 {
329 Kate::Command *p = KateCmd::self()->queryCommand (cmd);
330
331 m_oldText = cmd;
332 m_msgMode = true;
333
334 if (p)
335 {
336 TQString msg;
337
338 if (p->exec (m_view, cmd, msg))
339 {
340 KateCmd::self()->appendHistory( cmd );
341 m_histpos = KateCmd::self()->historyLength();
342 m_oldText = TQString ();
343
344 if (msg.length() > 0)
345 setText (i18n ("Success: ") + msg);
346 else
347 setText (i18n ("Success"));
348 }
349 else
350 {
351 if (msg.length() > 0)
352 setText (i18n ("Error: ") + msg);
353 else
354 setText (i18n ("Command \"%1\" failed.").arg (cmd));
355 KNotifyClient::beep();
356 }
357 }
358 else
359 {
360 setText (i18n ("No such command: \"%1\"").arg (cmd));
361 KNotifyClient::beep();
362 }
363 }
364
365 // clean up
366 if ( m_oldCompletionObject )
367 {
368 TDECompletion *c = completionObject();
369 setCompletionObject( m_oldCompletionObject );
370 m_oldCompletionObject = 0;
371 delete c;
372 c = 0;
373 }
374 m_command = 0;
375 m_cmdend = 0;
376
377 m_view->setFocus ();
378 TQTimer::singleShot( 4000, this, TQ_SLOT(hideMe()) );
379}
380
381void KateCmdLine::hideMe () // unless i have focus ;)
382{
383 if ( isVisibleTo(parentWidget()) && ! hasFocus() ) {
384 m_view->toggleCmdLine ();
385 }
386}
387
388void KateCmdLine::focusInEvent ( TQFocusEvent *ev )
389{
390 if (m_msgMode)
391 {
392 m_msgMode = false;
393 setText (m_oldText);
394 selectAll();
395 }
396
397 KLineEdit::focusInEvent (ev);
398}
399
400void KateCmdLine::keyPressEvent( TQKeyEvent *ev )
401{
402 if (ev->key() == Key_Escape)
403 {
404 m_view->setFocus ();
405 hideMe();
406 }
407 else if ( ev->key() == Key_Up )
408 fromHistory( true );
409 else if ( ev->key() == Key_Down )
410 fromHistory( false );
411
412 uint cursorpos = cursorPosition();
413 KLineEdit::keyPressEvent (ev);
414
415 // during typing, let us see if we have a valid command
416 if ( ! m_cmdend || cursorpos <= m_cmdend )
417 {
418 TQChar c;
419 if ( ! ev->text().isEmpty() )
420 c = ev->text()[0];
421
422 if ( ! m_cmdend && ! c.isNull() ) // we have no command, so lets see if we got one
423 {
424 if ( ! c.isLetterOrNumber() && c != '-' && c != '_' )
425 {
426 m_command = KateCmd::self()->queryCommand( text().stripWhiteSpace() );
427 if ( m_command )
428 {
429 //kdDebug(13025)<<"keypress in commandline: We have a command! "<<m_command<<". text is '"<<text()<<"'"<<endl;
430 // if the typed character is ":",
431 // we try if the command has flag completions
432 m_cmdend = cursorpos;
433 //kdDebug(13025)<<"keypress in commandline: Set m_cmdend to "<<m_cmdend<<endl;
434 }
435 else
436 m_cmdend = 0;
437 }
438 }
439 else // since cursor is inside the command name, we reconsider it
440 {
441 kdDebug(13025)<<"keypress in commandline: \\W -- text is "<<text()<<endl;
442 m_command = KateCmd::self()->queryCommand( text().stripWhiteSpace() );
443 if ( m_command )
444 {
445 //kdDebug(13025)<<"keypress in commandline: We have a command! "<<m_command<<endl;
446 TQString t = text();
447 m_cmdend = 0;
448 bool b = false;
449 for ( ; m_cmdend < t.length(); m_cmdend++ )
450 {
451 if ( t[m_cmdend].isLetter() )
452 b = true;
453 if ( b && ( ! t[m_cmdend].isLetterOrNumber() && t[m_cmdend] != '-' && t[m_cmdend] != '_' ) )
454 break;
455 }
456
457 if ( c == ':' && cursorpos == m_cmdend )
458 {
459 // check if this command wants to complete flags
460 //kdDebug(13025)<<"keypress in commandline: Checking if flag completion is desired!"<<endl;
461 }
462 }
463 else
464 {
465 // clean up if needed
466 if ( m_oldCompletionObject )
467 {
468 TDECompletion *c = completionObject();
469 setCompletionObject( m_oldCompletionObject );
470 m_oldCompletionObject = 0;
471 delete c;
472 c = 0;
473 }
474
475 m_cmdend = 0;
476 }
477 }
478
479 // if we got a command, check if it wants to do semething.
480 if ( m_command )
481 {
482 //kdDebug(13025)<<"Checking for CommandExtension.."<<endl;
483 Kate::CommandExtension *ce = dynamic_cast<Kate::CommandExtension*>(m_command);
484 if ( ce )
485 {
486 TDECompletion *cmpl = ce->completionObject( text().left( m_cmdend ).stripWhiteSpace(), m_view );
487 if ( cmpl )
488 {
489 // save the old completion object and use what the command provides
490 // instead. We also need to prepend the current command name + flag string
491 // when completion is done
492 //kdDebug(13025)<<"keypress in commandline: Setting completion object!"<<endl;
493 if ( ! m_oldCompletionObject )
494 m_oldCompletionObject = completionObject();
495
496 setCompletionObject( cmpl );
497 }
498 }
499 }
500 }
501 else if ( m_command )// check if we should call the commands processText()
502 {
503 Kate::CommandExtension *ce = dynamic_cast<Kate::CommandExtension*>( m_command );
504 if ( ce && ce->wantsToProcessText( text().left( m_cmdend ).stripWhiteSpace() )
505 && ! ( ev->text().isNull() || ev->text().isEmpty() ) )
506 ce->processText( m_view, text() );
507 }
508}
509
510void KateCmdLine::fromHistory( bool up )
511{
512 if ( ! KateCmd::self()->historyLength() )
513 return;
514
515 TQString s;
516
517 if ( up )
518 {
519 if ( m_histpos > 0 )
520 {
521 m_histpos--;
522 s = KateCmd::self()->fromHistory( m_histpos );
523 }
524 }
525 else
526 {
527 if ( m_histpos < ( KateCmd::self()->historyLength() - 1 ) )
528 {
529 m_histpos++;
530 s = KateCmd::self()->fromHistory( m_histpos );
531 }
532 else
533 {
534 m_histpos = KateCmd::self()->historyLength();
535 setText( m_oldText );
536 }
537 }
538 if ( ! s.isEmpty() )
539 {
540 // Select the argument part of the command, so that it is easy to overwrite
541 setText( s );
542 static TQRegExp reCmd = TQRegExp(".*[\\w\\-]+(?:[^a-zA-Z0-9_-]|:\\w+)(.*)");
543 if ( reCmd.search( text() ) == 0 )
544 setSelection( text().length() - reCmd.cap(1).length(), reCmd.cap(1).length() );
545 }
546}
547//END KateCmdLine
548
549//BEGIN KateIconBorder
550using namespace KTextEditor;
551
552static const char* const plus_xpm[] = {
553"11 11 3 1",
554" c None",
555". c #000000",
556"+ c #FFFFFF",
557"...........",
558".+++++++++.",
559".+++++++++.",
560".++++.++++.",
561".++++.++++.",
562".++.....++.",
563".++++.++++.",
564".++++.++++.",
565".+++++++++.",
566".+++++++++.",
567"..........."};
568
569static const char* const minus_xpm[] = {
570"11 11 3 1",
571" c None",
572". c #000000",
573"+ c #FFFFFF",
574"...........",
575".+++++++++.",
576".+++++++++.",
577".+++++++++.",
578".+++++++++.",
579".++.....++.",
580".+++++++++.",
581".+++++++++.",
582".+++++++++.",
583".+++++++++.",
584"..........."};
585
586static const char * const bookmark_xpm[] = {
587"14 13 82 1",
588" c None",
589". c #F27D01",
590"+ c #EF7901",
591"@ c #F3940F",
592"# c #EE8F12",
593"$ c #F9C834",
594"% c #F5C33A",
595"& c #F09110",
596"* c #FCEE3E",
597"= c #FBEB3F",
598"- c #E68614",
599"; c #FA8700",
600"> c #F78703",
601", c #F4920E",
602"' c #F19113",
603") c #F6C434",
604"! c #FDF938",
605"~ c #FDF839",
606"{ c #F1BC3A",
607"] c #E18017",
608"^ c #DA7210",
609"/ c #D5680B",
610"( c #CA5404",
611"_ c #FD8F06",
612": c #FCB62D",
613"< c #FDE049",
614"[ c #FCE340",
615"} c #FBE334",
616"| c #FDF035",
617"1 c #FEF834",
618"2 c #FCEF36",
619"3 c #F8DF32",
620"4 c #F7DC3D",
621"5 c #F5CE3E",
622"6 c #DE861B",
623"7 c #C64C03",
624"8 c #F78C07",
625"9 c #F8B019",
626"0 c #FDE12D",
627"a c #FEE528",
628"b c #FEE229",
629"c c #FBD029",
630"d c #E18814",
631"e c #CB5605",
632"f c #EF8306",
633"g c #F3A00E",
634"h c #FBC718",
635"i c #FED31C",
636"j c #FED11D",
637"k c #F8B91C",
638"l c #E07D0D",
639"m c #CB5301",
640"n c #ED8A0E",
641"o c #F7A90D",
642"p c #FEC113",
643"q c #FEC013",
644"r c #F09B0E",
645"s c #D35E03",
646"t c #EF9213",
647"u c #F9A208",
648"v c #FEAA0C",
649"w c #FCA10B",
650"x c #FCA70B",
651"y c #FEAF0B",
652"z c #F39609",
653"A c #D86203",
654"B c #F08C0D",
655"C c #FA9004",
656"D c #F17F04",
657"E c #E36D04",
658"F c #E16F03",
659"G c #EE8304",
660"H c #F88C04",
661"I c #DC6202",
662"J c #E87204",
663"K c #E66A01",
664"L c #DC6001",
665"M c #D15601",
666"N c #DA5D01",
667"O c #D25200",
668"P c #DA5F00",
669"Q c #BC3C00",
670" .+ ",
671" @# ",
672" $% ",
673" &*=- ",
674" ;>,')!~{]^/( ",
675"_:<[}|11234567",
676" 890aaaaabcde ",
677" fghiiijklm ",
678" nopqpqrs ",
679" tuvwxyzA ",
680" BCDEFGHI ",
681" JKL MNO ",
682" P Q "};
683
684const int iconPaneWidth = 16;
685const int halfIPW = 8;
686
687KateIconBorder::KateIconBorder ( KateViewInternal* internalView, TQWidget *parent )
688 : TQWidget(parent, "", (WFlags)(WStaticContents | WRepaintNoErase | WResizeNoErase) )
689 , m_view( internalView->m_view )
690 , m_doc( internalView->m_doc )
691 , m_viewInternal( internalView )
692 , m_iconBorderOn( false )
693 , m_lineNumbersOn( false )
694 , m_foldingMarkersOn( false )
695 , m_dynWrapIndicatorsOn( false )
696 , m_dynWrapIndicators( 0 )
697 , m_cachedLNWidth( 0 )
698 , m_maxCharWidth( 0 )
699{
700 setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Minimum ) );
701
702 setBackgroundMode( NoBackground );
703
704 m_doc->setDescription( MarkInterface::markType01, i18n("Bookmark") );
705 m_doc->setPixmap( MarkInterface::markType01, TQPixmap((const char**)bookmark_xpm) );
706
707 updateFont();
708}
709
710void KateIconBorder::setIconBorderOn( bool enable )
711{
712 if( enable == m_iconBorderOn )
713 return;
714
715 m_iconBorderOn = enable;
716
717 updateGeometry();
718
719 TQTimer::singleShot( 0, this, TQ_SLOT(update()) );
720}
721
722void KateIconBorder::setLineNumbersOn( bool enable )
723{
724 if( enable == m_lineNumbersOn )
725 return;
726
727 m_lineNumbersOn = enable;
728 m_dynWrapIndicatorsOn = (m_dynWrapIndicators == 1) ? enable : m_dynWrapIndicators;
729
730 updateGeometry();
731
732 TQTimer::singleShot( 0, this, TQ_SLOT(update()) );
733}
734
735void KateIconBorder::setDynWrapIndicators( int state )
736{
737 if (state == m_dynWrapIndicators )
738 return;
739
740 m_dynWrapIndicators = state;
741 m_dynWrapIndicatorsOn = (state == 1) ? m_lineNumbersOn : state;
742
743 updateGeometry ();
744
745 TQTimer::singleShot( 0, this, TQ_SLOT(update()) );
746}
747
748void KateIconBorder::setFoldingMarkersOn( bool enable )
749{
750 if( enable == m_foldingMarkersOn )
751 return;
752
753 m_foldingMarkersOn = enable;
754
755 updateGeometry();
756
757 TQTimer::singleShot( 0, this, TQ_SLOT(update()) );
758}
759
760TQSize KateIconBorder::sizeHint() const
761{
762 int w = 0;
763
764 if (m_iconBorderOn)
765 w += iconPaneWidth + 1;
766
767 if (m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn)) {
768 w += lineNumberWidth();
769 }
770
771 if (m_foldingMarkersOn)
772 w += iconPaneWidth;
773
774 w += 4;
775
776 return TQSize( w, 0 );
777}
778
779// This function (re)calculates the maximum width of any of the digit characters (0 -> 9)
780// for graceful handling of variable-width fonts as the linenumber font.
781void KateIconBorder::updateFont()
782{
783 const TQFontMetrics *fm = m_view->renderer()->config()->fontMetrics();
784 m_maxCharWidth = 0;
785 // Loop to determine the widest numeric character in the current font.
786 // 48 is ascii '0'
787 for (int i = 48; i < 58; i++) {
788 int charWidth = fm->width( TQChar(i) );
789 m_maxCharWidth = kMax(m_maxCharWidth, charWidth);
790 }
791}
792
793int KateIconBorder::lineNumberWidth() const
794{
795 int width = m_lineNumbersOn ? ((int)log10((double)(m_view->doc()->numLines())) + 1) * m_maxCharWidth + 4 : 0;
796
797 if (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) {
798 width = kMax(style().scrollBarExtent().width() + 4, width);
799
800 if (m_cachedLNWidth != width || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor()) {
801 int w = style().scrollBarExtent().width();
802 int h = m_view->renderer()->config()->fontMetrics()->height();
803
804 TQSize newSize(w, h);
805 if ((m_arrow.size() != newSize || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor()) && !newSize.isEmpty()) {
806 m_arrow.resize(newSize);
807
808 TQPainter p(&m_arrow);
809 p.fillRect( 0, 0, w, h, m_view->renderer()->config()->iconBarColor() );
810
811 h = m_view->renderer()->config()->fontMetrics()->ascent();
812
813 p.setPen(m_view->renderer()->attribute(0)->textColor());
814 p.drawLine(w/2, h/2, w/2, 0);
815#if 1
816 p.lineTo(w/4, h/4);
817 p.lineTo(0, 0);
818 p.lineTo(0, h/2);
819 p.lineTo(w/2, h-1);
820 p.lineTo(w*3/4, h-1);
821 p.lineTo(w-1, h*3/4);
822 p.lineTo(w*3/4, h/2);
823 p.lineTo(0, h/2);
824#else
825 p.lineTo(w*3/4, h/4);
826 p.lineTo(w-1,0);
827 p.lineTo(w-1, h/2);
828 p.lineTo(w/2, h-1);
829 p.lineTo(w/4,h-1);
830 p.lineTo(0, h*3/4);
831 p.lineTo(w/4, h/2);
832 p.lineTo(w-1, h/2);
833#endif
834 }
835 }
836 }
837
838 return width;
839}
840
841void KateIconBorder::paintEvent(TQPaintEvent* e)
842{
843 paintBorder(e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height());
844}
845
846void KateIconBorder::paintBorder (int /*x*/, int y, int /*width*/, int height)
847{
848 static TQPixmap minus_px ((const char**)minus_xpm);
849 static TQPixmap plus_px ((const char**)plus_xpm);
850
851 uint h = m_view->renderer()->config()->fontStruct()->fontHeight;
852 uint startz = (y / h);
853 uint endz = startz + 1 + (height / h);
854 uint lineRangesSize = m_viewInternal->lineRanges.size();
855
856 // center the folding boxes
857 int m_px = (h - 11) / 2;
858 if (m_px < 0)
859 m_px = 0;
860
861 int lnWidth( 0 );
862 if ( m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) ) // avoid calculating unless needed ;-)
863 {
864 lnWidth = lineNumberWidth();
865 if ( lnWidth != m_cachedLNWidth || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor() )
866 {
867 // we went from n0 ->n9 lines or vice verca
868 // this causes an extra updateGeometry() first time the line numbers
869 // are displayed, but sizeHint() is supposed to be const so we can't set
870 // the cached value there.
871 m_cachedLNWidth = lnWidth;
872 m_oldBackgroundColor = m_view->renderer()->config()->iconBarColor();
873 updateGeometry();
874 update ();
875 return;
876 }
877 }
878
879 int w( this->width() ); // sane value/calc only once
880
881 TQPainter p ( this );
882 p.setFont ( *m_view->renderer()->config()->font() ); // for line numbers
883 // the line number color is for the line numbers, vertical separator lines
884 // and for for the code folding lines.
885 p.setPen ( m_view->renderer()->config()->lineNumberColor() );
886
887 KateLineInfo oldInfo;
888 if (startz < lineRangesSize)
889 {
890 if ((m_viewInternal->lineRanges[startz].line-1) < 0)
891 oldInfo.topLevel = true;
892 else
893 m_doc->lineInfo(&oldInfo,m_viewInternal->lineRanges[startz].line-1);
894 }
895
896 for (uint z=startz; z <= endz; z++)
897 {
898 int y = h * z;
899 int realLine = -1;
900
901 if (z < lineRangesSize)
902 realLine = m_viewInternal->lineRanges[z].line;
903
904 int lnX ( 0 );
905
906 p.fillRect( 0, y, w-4, h, m_view->renderer()->config()->iconBarColor() );
907 p.fillRect( w-4, y, 4, h, m_view->renderer()->config()->backgroundColor() );
908
909 // icon pane
910 if( m_iconBorderOn )
911 {
912 p.drawLine(lnX+iconPaneWidth, y, lnX+iconPaneWidth, y+h);
913
914 if( (realLine > -1) && (m_viewInternal->lineRanges[z].startCol == 0) )
915 {
916 uint mrk ( m_doc->mark( realLine ) ); // call only once
917
918 if ( mrk )
919 {
920 for( uint bit = 0; bit < 32; bit++ )
921 {
922 MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1<<bit);
923 if( mrk & markType )
924 {
925 TQPixmap *px_mark (m_doc->markPixmap( markType ));
926
927 if (px_mark)
928 {
929 // center the mark pixmap
930 int x_px = (iconPaneWidth - px_mark->width()) / 2;
931 if (x_px < 0)
932 x_px = 0;
933
934 int y_px = (h - px_mark->height()) / 2;
935 if (y_px < 0)
936 y_px = 0;
937
938 p.drawPixmap( lnX+x_px, y+y_px, *px_mark);
939 }
940 }
941 }
942 }
943 }
944
945 lnX += iconPaneWidth + 1;
946 }
947
948 // line number
949 if( m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) )
950 {
951 lnX +=2;
952
953 if (realLine > -1)
954 if (m_viewInternal->lineRanges[z].startCol == 0) {
955 if (m_lineNumbersOn)
956 p.drawText( lnX + 1, y, lnWidth-4, h, TQt::AlignRight|TQt::AlignVCenter, TQString("%1").arg( realLine + 1 ) );
957 } else if (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) {
958 p.drawPixmap(lnX + lnWidth - m_arrow.width() - 4, y, m_arrow);
959 }
960
961 lnX += lnWidth;
962 }
963
964 // folding markers
965 if( m_foldingMarkersOn )
966 {
967 if( realLine > -1 )
968 {
969 KateLineInfo info;
970 m_doc->lineInfo(&info,realLine);
971
972 if (!info.topLevel)
973 {
974 if (info.startsVisibleBlock && (m_viewInternal->lineRanges[z].startCol == 0))
975 {
976 if (oldInfo.topLevel)
977 p.drawLine(lnX+halfIPW,y+m_px,lnX+halfIPW,y+h-1);
978 else
979 p.drawLine(lnX+halfIPW,y,lnX+halfIPW,y+h-1);
980
981 p.drawPixmap(lnX+3,y+m_px,minus_px);
982 }
983 else if (info.startsInVisibleBlock)
984 {
985 if (m_viewInternal->lineRanges[z].startCol == 0)
986 {
987 if (oldInfo.topLevel)
988 p.drawLine(lnX+halfIPW,y+m_px,lnX+halfIPW,y+h-1);
989 else
990 p.drawLine(lnX+halfIPW,y,lnX+halfIPW,y+h-1);
991
992 p.drawPixmap(lnX+3,y+m_px,plus_px);
993 }
994 else
995 {
996 p.drawLine(lnX+halfIPW,y,lnX+halfIPW,y+h-1);
997 }
998
999 if (!m_viewInternal->lineRanges[z].wrap)
1000 p.drawLine(lnX+halfIPW,y+h-1,lnX+iconPaneWidth-2,y+h-1);
1001 }
1002 else
1003 {
1004 p.drawLine(lnX+halfIPW,y,lnX+halfIPW,y+h-1);
1005
1006 if (info.endsBlock && !m_viewInternal->lineRanges[z].wrap)
1007 p.drawLine(lnX+halfIPW,y+h-1,lnX+iconPaneWidth-2,y+h-1);
1008 }
1009 }
1010
1011 oldInfo = info;
1012 }
1013
1014 lnX += iconPaneWidth;
1015 }
1016 }
1017}
1018
1019KateIconBorder::BorderArea KateIconBorder::positionToArea( const TQPoint& p ) const
1020{
1021 int x = 0;
1022 if( m_iconBorderOn ) {
1023 x += iconPaneWidth;
1024 if( p.x() <= x )
1025 return IconBorder;
1026 }
1027 if( m_lineNumbersOn || m_dynWrapIndicators ) {
1028 x += lineNumberWidth();
1029 if( p.x() <= x )
1030 return LineNumbers;
1031 }
1032 if( m_foldingMarkersOn ) {
1033 x += iconPaneWidth;
1034 if( p.x() <= x )
1035 return FoldingMarkers;
1036 }
1037 return None;
1038}
1039
1040void KateIconBorder::mousePressEvent( TQMouseEvent* e )
1041{
1042 m_lastClickedLine = m_viewInternal->yToKateLineRange(e->y()).line;
1043
1044 if ( positionToArea( e->pos() ) != IconBorder )
1045 {
1046 TQMouseEvent forward( TQEvent::MouseButtonPress,
1047 TQPoint( 0, e->y() ), e->button(), e->state() );
1048 m_viewInternal->mousePressEvent( &forward );
1049 }
1050 e->accept();
1051}
1052
1053void KateIconBorder::mouseMoveEvent( TQMouseEvent* e )
1054{
1055 if ( positionToArea( e->pos() ) != IconBorder )
1056 {
1057 TQMouseEvent forward( TQEvent::MouseMove,
1058 TQPoint( 0, e->y() ), e->button(), e->state() );
1059 m_viewInternal->mouseMoveEvent( &forward );
1060 }
1061}
1062
1063void KateIconBorder::mouseReleaseEvent( TQMouseEvent* e )
1064{
1065 uint cursorOnLine = m_viewInternal->yToKateLineRange(e->y()).line;
1066
1067 if (cursorOnLine == m_lastClickedLine &&
1068 cursorOnLine <= m_doc->lastLine() )
1069 {
1070 BorderArea area = positionToArea( e->pos() );
1071 if( area == IconBorder) {
1072 if (e->button() == TQt::LeftButton) {
1073 if( m_doc->editableMarks() & KateViewConfig::global()->defaultMarkType() ) {
1074 if( m_doc->mark( cursorOnLine ) & KateViewConfig::global()->defaultMarkType() )
1075 m_doc->removeMark( cursorOnLine, KateViewConfig::global()->defaultMarkType() );
1076 else
1077 m_doc->addMark( cursorOnLine, KateViewConfig::global()->defaultMarkType() );
1078 } else {
1079 showMarkMenu( cursorOnLine, TQCursor::pos() );
1080 }
1081 }
1082 else
1083 if (e->button() == TQt::RightButton) {
1084 showMarkMenu( cursorOnLine, TQCursor::pos() );
1085 }
1086 }
1087
1088 if ( area == FoldingMarkers) {
1089 KateLineInfo info;
1090 m_doc->lineInfo(&info,cursorOnLine);
1091 if ((info.startsVisibleBlock) || (info.startsInVisibleBlock)) {
1092 emit toggleRegionVisibility(cursorOnLine);
1093 }
1094 }
1095 }
1096
1097 TQMouseEvent forward( TQEvent::MouseButtonRelease,
1098 TQPoint( 0, e->y() ), e->button(), e->state() );
1099 m_viewInternal->mouseReleaseEvent( &forward );
1100}
1101
1102void KateIconBorder::mouseDoubleClickEvent( TQMouseEvent* e )
1103{
1104 TQMouseEvent forward( TQEvent::MouseButtonDblClick,
1105 TQPoint( 0, e->y() ), e->button(), e->state() );
1106 m_viewInternal->mouseDoubleClickEvent( &forward );
1107}
1108
1109void KateIconBorder::showMarkMenu( uint line, const TQPoint& pos )
1110{
1111 TQPopupMenu markMenu;
1112 TQPopupMenu selectDefaultMark;
1113
1114 typedef TQValueVector<int> MarkTypeVector;
1115 MarkTypeVector vec( 33 );
1116 int i=1;
1117
1118 for( uint bit = 0; bit < 32; bit++ ) {
1119 MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1<<bit);
1120 if( !(m_doc->editableMarks() & markType) )
1121 continue;
1122
1123 if( !m_doc->markDescription( markType ).isEmpty() ) {
1124 markMenu.insertItem( m_doc->markDescription( markType ), i );
1125 selectDefaultMark.insertItem( m_doc->markDescription( markType ), i+100);
1126 } else {
1127 markMenu.insertItem( i18n("Mark Type %1").arg( bit + 1 ), i );
1128 selectDefaultMark.insertItem( i18n("Mark Type %1").arg( bit + 1 ), i+100);
1129 }
1130
1131 if( m_doc->mark( line ) & markType )
1132 markMenu.setItemChecked( i, true );
1133
1134 if( markType & KateViewConfig::global()->defaultMarkType() )
1135 selectDefaultMark.setItemChecked( i+100, true );
1136
1137 vec[i++] = markType;
1138 }
1139
1140 if( markMenu.count() == 0 )
1141 return;
1142
1143 if( markMenu.count() > 1 )
1144 markMenu.insertItem( i18n("Set Default Mark Type" ), &selectDefaultMark);
1145
1146 int result = markMenu.exec( pos );
1147 if( result <= 0 )
1148 return;
1149
1150 if ( result > 100)
1151 {
1152 KateViewConfig::global()->setDefaultMarkType (vec[result-100]);
1153 // flush config, otherwise it isn't nessecarily done
1154 TDEConfig *config = tdeApp->config();
1155 config->setGroup("Kate View Defaults");
1156 KateViewConfig::global()->writeConfig( config );
1157 }
1158 else
1159 {
1160 MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes) vec[result];
1161 if( m_doc->mark( line ) & markType ) {
1162 m_doc->removeMark( line, markType );
1163 } else {
1164 m_doc->addMark( line, markType );
1165 }
1166 }
1167}
1168//END KateIconBorder
1169
1170KateViewEncodingAction::KateViewEncodingAction(KateDocument *_doc, KateView *_view, const TQString& text, TQObject* parent, const char* name)
1171 : TDEActionMenu (text, parent, name), doc(_doc), view (_view)
1172{
1173 connect(popupMenu(),TQ_SIGNAL(aboutToShow()),this,TQ_SLOT(slotAboutToShow()));
1174}
1175
1176void KateViewEncodingAction::slotAboutToShow()
1177{
1178 TQStringList modes (TDEGlobal::charsets()->descriptiveEncodingNames());
1179
1180 popupMenu()->clear ();
1181 for (uint z=0; z<modes.size(); ++z)
1182 {
1183 popupMenu()->insertItem ( modes[z], this, TQ_SLOT(setMode(int)), 0, z);
1184
1185 bool found = false;
1186 TQTextCodec *codecForEnc = TDEGlobal::charsets()->codecForName(TDEGlobal::charsets()->encodingForName(modes[z]), found);
1187
1188 if (found && codecForEnc)
1189 {
1190 if (codecForEnc->name() == doc->config()->codec()->name())
1191 popupMenu()->setItemChecked (z, true);
1192 }
1193 }
1194}
1195
1196void KateViewEncodingAction::setMode (int mode)
1197{
1198 TQStringList modes (TDEGlobal::charsets()->descriptiveEncodingNames());
1199 doc->config()->setEncoding( TDEGlobal::charsets()->encodingForName( modes[mode] ) );
1200 // now we don't want the encoding changed again unless the user does so using the menu.
1201 doc->setEncodingSticky( true );
1202 doc->reloadFile();
1203}
KCharsets::codecForName
TQTextCodec * codecForName(const TQString &name) const
KLineEdit
KLineEdit::focusInEvent
virtual void focusInEvent(TQFocusEvent *)
KLineEdit::keyPressEvent
virtual void keyPressEvent(TQKeyEvent *)
Kate::CommandExtension
Extension to the Command interface, allowing to interact with commands during typing.
Definition: document.h:130
Kate::CommandExtension::wantsToProcessText
virtual bool wantsToProcessText(const TQString &cmdname)
Definition: document.h:169
Kate::CommandExtension::processText
virtual void processText(Kate::View *view, const TQString &text)
This is called by the commandline each time the argument text for the command changes,...
Definition: document.h:177
Kate::CommandExtension::completionObject
virtual TDECompletion * completionObject(const TQString &cmdname, Kate::View *)
Definition: document.h:157
Kate::Command
Kate Commands.
Definition: document.h:97
Kate::Command::help
virtual bool help(View *view, const TQString &cmd, TQString &msg)=0
Shows help for the given view and cmd string, return a bool about success, msg for status.
Kate::Command::exec
virtual bool exec(View *view, const TQString &cmd, TQString &msg)=0
Execute this command for the given view and cmd string, return a bool about success,...
Kate::View
The Kate::View text editor interface.
Definition: view.h:45
TDEActionMenu
TDECompletion
TDECompletion::makeCompletion
virtual TQString makeCompletion(const TQString &string)
TDEConfigBase::setGroup
void setGroup(const TQString &group)
TDEConfig
TDEGlobal::charsets
static KCharsets * charsets()
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
KNotifyClient::beep
void beep(const TQString &reason=TQString::null)
KStdAction::clear
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEStdAccel::forward
const TDEShortcut & forward()
TDEStdAccel::name
TQString name(StdAccel id)
TDEStdAccel::end
const TDEShortcut & end()
TDEStdAccel::selectAll
const TDEShortcut & selectAll()
tdelocale.h

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.9.4
This website is maintained by Timothy Pearson.