-rw-r--r-- | noncore/apps/tinykate/libkate/view/kateview.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp index 8f3a25e..6453458 100644 --- a/noncore/apps/tinykate/libkate/view/kateview.cpp +++ b/noncore/apps/tinykate/libkate/view/kateview.cpp @@ -1,72 +1,72 @@ /*************************************************************************** kateview.cpp - description ------------------- begin : Mon Jan 15 2001 copyright : (C) 2001 by Christoph "Crossfire" Cullmann - (C) 2002 by Joseph Wenninger + (C) 2002 by Joseph Wenninger email : crossfire@babylon2k.de - jowenn@kde.org + jowenn@kde.org ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* Copyright (C) 1998, 1999 Jochen Wilhelmy digisnap@cs.tu-berlin.de This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "kateview.h" #include "../document/katedocument.h" #include "../document/katecmd.h" #include "../document/katehighlight.h" #include "kateviewdialog.h" #include "../document/katedialogs.h" #include <qfocusdata.h> #include <kdebug.h> #include <kapplication.h> #include <qscrollbar.h> #include <qiodevice.h> #include <qpopupmenu.h> #include <kpopupmenu.h> #include <qkeycode.h> #include <qintdict.h> #include <kconfig.h> #include <qfont.h> #include <qpainter.h> #include <qpixmap.h> #include <qfileinfo.h> #include <qfile.h> #include <qevent.h> #include <qdir.h> #include <qvbox.h> #include <qprintdialog.h> #include <qpaintdevicemetrics.h> #include <qiodevice.h> #include <qbuffer.h> #include <qfocusdata.h> @@ -1712,129 +1712,129 @@ void KateView::toggleVertical() int KateView::numLines() { return myDoc->numLines(); } QString KateView::text() { return myDoc->text(); } QString KateView::currentTextLine() { TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y); return QString(textLine->getText(), textLine->length()); } QString KateView::textLine(int num) { TextLine::Ptr textLine = myDoc->getTextLine(num); return QString(textLine->getText(), textLine->length()); } QString KateView::currentWord() { return myDoc->getWord(myViewInternal->cursor); } QString KateView::word(int x, int y) { PointStruc cursor; cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight; if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString(); cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x); return myDoc->getWord(cursor); } void KateView::setText(const QString &s) { myDoc->setText(s); myDoc->updateViews(); } void KateView::insertText(const QString &s, bool /*mark*/) { VConfig c; myViewInternal->getVConfig(c); myDoc->insert(c, s); myDoc->updateViews(); } bool KateView::hasMarkedText() { return myDoc->hasMarkedText(); } QString KateView::markedText() { return myDoc->markedText(configFlags); } bool KateView::canDiscard() { int query; if (isModified()) { query = KMessageBox::warningYesNoCancel(this, i18n("The current Document has been modified.\nWould you like to save it?")); switch (query) { case KMessageBox::Yes: //yes if (save() == CANCEL) return false; if (isModified()) { query = KMessageBox::warningContinueCancel(this, i18n("Could not save the document.\nDiscard it and continue?"), - QString::null, i18n("&Discard")); + QString::null, i18n("&Discard")); if (query == KMessageBox::Cancel) return false; } break; case KMessageBox::Cancel: //cancel return false; } } return true; } void KateView::flush() { if (canDiscard()) myDoc->flush(); } KateView::fileResult KateView::save() { int query = KMessageBox::Yes; if (isModified()) { return saveAs(); } return OK; } KateView::fileResult KateView::saveAs() { return OK; } void KateView::doCursorCommand(int cmdNum) { VConfig c; myViewInternal->getVConfig(c); if (cmdNum & selectFlag) c.flags |= KateView::cfMark; if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection; cmdNum &= ~(selectFlag | multiSelectFlag); myViewInternal->doCursorCommand(c, cmdNum); myDoc->updateViews(); } void KateView::doEditCommand(int cmdNum) { VConfig c; myViewInternal->getVConfig(c); myViewInternal->doEditCommand(c, cmdNum); myDoc->updateViews(); } void KateView::undoMultiple(int count) { if (isReadOnly()) return; VConfig c; myViewInternal->getVConfig(c); myDoc->undo(c, count); myDoc->updateViews(); } void KateView::redoMultiple(int count) { if (isReadOnly()) return; VConfig c; myViewInternal->getVConfig(c); myDoc->redo(c, count); myDoc->updateViews(); } @@ -2136,129 +2136,129 @@ void KateView::doReplaceAction(int result, bool found) { connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot())); replacePrompt->show(); //this is not modal } return; //exit if text found } //nothing found: repeat until user cancels "repeat from beginning" dialog } while (!askReplaceEnd()); deleteReplacePrompt(); } void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) { int x1, x2, y1, y2, xPos, yPos; VConfig c; myViewInternal->getVConfig(c); myDoc->selectLength(cursor,slen,c.flags); TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); x1 = myDoc->textWidth(textLine,cursor.x) -10; x2 = myDoc->textWidth(textLine,cursor.x + slen) +20; y1 = myDoc->fontHeight*cursor.y -10; y2 = y1 + myDoc->fontHeight +30; xPos = myViewInternal->xPos; yPos = myViewInternal->yPos; if (x1 < 0) x1 = 0; if (replace) y2 += 90; if (x1 < xPos || x2 > xPos + myViewInternal->width()) { xPos = x2 - myViewInternal->width(); } if (y1 < yPos || y2 > yPos + myViewInternal->height()) { xPos = x2 - myViewInternal->width(); yPos = myDoc->fontHeight*cursor.y - height()/3; } myViewInternal->setPos(xPos, yPos); myViewInternal->updateView(flags);// | ufPos,xPos,yPos); myDoc->updateViews(this); } void KateView::deleteReplacePrompt() { myDoc->setPseudoModal(0L); } bool KateView::askReplaceEnd() { QString str; int query; myDoc->updateViews(); if (s.flags & KateView::sfFinished) { // replace finished str = i18n("%1 replacement(s) made").arg(replaces); KMessageBox::information(this, str, i18n("Replace")); return true; } // ask for continue if (!(s.flags & KateView::sfBackward)) { // forward search str = i18n("%1 replacement(s) made.\n" "End of document reached.\n" "Continue from the beginning?").arg(replaces); query = KMessageBox::questionYesNo(this, str, i18n("Replace"), - i18n("Continue"), i18n("Stop")); + i18n("Continue"), i18n("Stop")); } else { // backward search str = i18n("%1 replacement(s) made.\n" "Beginning of document reached.\n" "Continue from the end?").arg(replaces); query = KMessageBox::questionYesNo(this, str, i18n("Replace"), i18n("Continue"), i18n("Stop")); } replaces = 0; continueSearch(s); return (query == KMessageBox::No); } void KateView::replaceSlot() { doReplaceAction(replacePrompt->result(),true); } void KateView::installPopup(QPopupMenu *rmb_Menu) { rmbMenu = rmb_Menu; } void KateView::readConfig() { KConfig *config = KGlobal::config(); config->setGroup("Kate View"); searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt); configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark; config->sync(); } void KateView::writeConfig() { KConfig *config = KGlobal::config(); config->setGroup("Kate View"); config->writeEntry("SearchFlags",searchFlags); config->writeEntry("ConfigFlags",configFlags); config->sync(); } void KateView::readSessionConfig(KConfig *config) { PointStruc cursor; myViewInternal->xPos = config->readNumEntry("XPos"); myViewInternal->yPos = config->readNumEntry("YPos"); cursor.x = config->readNumEntry("CursorX"); cursor.y = config->readNumEntry("CursorY"); myViewInternal->updateCursor(cursor); myIconBorder = config->readBoolEntry("IconBorder on"); setIconBorder(myIconBorder); } void KateView::writeSessionConfig(KConfig *config) { config->writeEntry("XPos",myViewInternal->xPos); config->writeEntry("YPos",myViewInternal->yPos); config->writeEntry("CursorX",myViewInternal->cursor.x); config->writeEntry("CursorY",myViewInternal->cursor.y); config->writeEntry("IconBorder on", myIconBorder); @@ -2266,129 +2266,129 @@ void KateView::writeSessionConfig(KConfig *config) void KateView::configDialog() { #warning fixme #if 1 KDialogBase *kd = new KDialogBase(KDialogBase::IconList, i18n("Configure Editor"), KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Help , KDialogBase::Ok, this, "tabdialog"); // color options QFrame *page=kd->addPage(i18n("Colors")); (new QVBoxLayout(page))->setAutoAdd(true); ColorConfig *colorConfig = new ColorConfig(page); QColor* colors = getColors(); colorConfig->setColors(colors); page = kd->addPage(i18n("Fonts")); (new QVBoxLayout(page))->setAutoAdd(true); FontConfig *fontConfig = new FontConfig(page); fontConfig->setFont (myDoc->getFont()); // indent options page=kd->addPage(i18n("Indent")); (new QVBoxLayout(page))->setAutoAdd(true); IndentConfigTab *indentConfig = new IndentConfigTab(page, this); // select options page=kd->addPage(i18n("Select")); (new QVBoxLayout(page))->setAutoAdd(true); SelectConfigTab *selectConfig = new SelectConfigTab(page, this); // edit options page=kd->addPage(i18n("Edit")); (new QVBoxLayout(page))->setAutoAdd(true); EditConfigTab *editConfig = new EditConfigTab(page, this); HighlightDialogPage *hlPage; HlManager *hlManager; HlDataList hlDataList; ItemStyleList defaultStyleList; hlManager = HlManager::self(); defaultStyleList.setAutoDelete(true); hlManager->getDefaults(defaultStyleList); hlDataList.setAutoDelete(true); //this gets the data from the KConfig object hlManager->getHlDataList(hlDataList); page=kd->addPage(i18n("Highlighting")); (new QVBoxLayout(page))->setAutoAdd(true); hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, page); - + kd->showMaximized(); if (kd->exec()) { // color options colorConfig->getColors(colors); myDoc->setFont (fontConfig->getFont()); applyColors(); // indent options indentConfig->getData(this); // select options selectConfig->getData(this); // edit options editConfig->getData(this); // spell checker hlManager->setHlDataList(hlDataList); hlManager->setDefaults(defaultStyleList); hlPage->saveData(); } delete kd; #endif } int KateView::getHl() { return myDoc->highlightNum(); } void KateView::setDontChangeHlOnSave() { myDoc->setDontChangeHlOnSave(); } void KateView::setHl(int n) { myDoc->setHighlight(n); myDoc->setDontChangeHlOnSave(); myDoc->updateViews(); } int KateView::getEol() { return myDoc->eolMode; } void KateView::setEol(int eol) { if (isReadOnly()) return; myDoc->eolMode = eol; myDoc->setModified(true); } void KateView::paintEvent(QPaintEvent *e) { int x, y; QRect updateR = e->rect(); // update rectangle // debug("Update rect = ( %i, %i, %i, %i )", // updateR.x(),updateR.y(), updateR.width(), updateR.height() ); int ux1 = updateR.x(); int uy1 = updateR.y(); int ux2 = ux1 + updateR.width(); int uy2 = uy1 + updateR.height(); @@ -2776,129 +2776,129 @@ const char*ddd_xpm[]={ "#a#b.......", "#b.........", "...........", "...........", "..........."}; KateIconBorder::KateIconBorder(KateView *view, KateViewInternal *internalView) : QWidget(view), myView(view), myInternalView(internalView) { lmbSetsBreakpoints = true; } KateIconBorder::~KateIconBorder() { } void KateIconBorder::paintLine(int i) { if (!myView->myIconBorder) return; QPainter p(this); int fontHeight = myView->doc()->fontHeight; int y = i*fontHeight - myInternalView->yPos; p.fillRect(0, y, myInternalView->iconBorderWidth-2, fontHeight, colorGroup().background()); p.setPen(white); p.drawLine(myInternalView->iconBorderWidth-2, y, myInternalView->iconBorderWidth-2, y + fontHeight); p.setPen(QColor(colorGroup().background()).dark()); p.drawLine(myInternalView->iconBorderWidth-1, y, myInternalView->iconBorderWidth-1, y + fontHeight); TextLine *line = myView->doc()->getTextLine(i); if (!line) return; if (line->mark()&KateDocument::Bookmark) p.drawPixmap(2, y, QPixmap(bookmark_xpm)); /* if (line && (line->breakpointId() != -1)) { if (!line->breakpointEnabled()) p.drawPixmap(2, y, QPixmap(breakpoint_gr_xpm)); else if (line->breakpointPending()) p.drawPixmap(2, y, QPixmap(breakpoint_bl_xpm)); else p.drawPixmap(2, y, QPixmap(breakpoint_xpm)); } if (line->isExecutionPoint()) p.drawPixmap(2, y, QPixmap(ddd_xpm)); */ } void KateIconBorder::paintEvent(QPaintEvent* e) { if (!myView->myIconBorder) return; int lineStart = 0; int lineEnd = 0; QRect updateR = e->rect(); KateDocument *doc = myView->doc(); int h = doc->fontHeight; int yPos = myInternalView->yPos; if (h) { - lineStart = (yPos + updateR.y()) / h; + lineStart = (yPos + updateR.y()) / h; lineEnd = QMAX((yPos + updateR.y() + updateR.height()) / h, (int)doc->numLines()); } for(int i = lineStart; i <= lineEnd; ++i) paintLine(i); } void KateIconBorder::mousePressEvent(QMouseEvent* e) { myInternalView->placeCursor( 0, e->y(), 0 ); KateDocument *doc = myView->doc(); int cursorOnLine = (e->y() + myInternalView->yPos) / doc->fontHeight; TextLine *line = doc->getTextLine(cursorOnLine); switch (e->button()) { case LeftButton: if (!line) break; else { if (line->mark()&KateDocument::Bookmark) line->delMark (KateDocument::Bookmark); else line->addMark (KateDocument::Bookmark); doc->tagLines(cursorOnLine, cursorOnLine); doc->updateViews(); } break; /* case RightButton: { if (!line) break; KPopupMenu popup; popup.setCheckable(true); popup.insertTitle(i18n("Breakpoints/Bookmarks")); int idToggleBookmark = popup.insertItem(i18n("Toggle bookmark")); popup.insertSeparator(); int idToggleBreakpoint = popup.insertItem(i18n("Toggle breakpoint")); int idEditBreakpoint = popup.insertItem(i18n("Edit breakpoint")); int idEnableBreakpoint = popup.insertItem(i18n("Disable breakpoint")); popup.insertSeparator(); popup.insertSeparator(); int idLmbSetsBreakpoints = popup.insertItem(i18n("LMB sets breakpoints")); int idLmbSetsBookmarks = popup.insertItem(i18n("LMB sets bookmarks")); popup.setItemChecked(idLmbSetsBreakpoints, lmbSetsBreakpoints); popup.setItemChecked(idLmbSetsBookmarks, !lmbSetsBreakpoints); if (line->breakpointId() == -1) { popup.setItemEnabled(idEditBreakpoint, false); popup.setItemEnabled(idEnableBreakpoint, false); popup.changeItem(idEnableBreakpoint, i18n("Enable breakpoint")); } int res = popup.exec(mapToGlobal(e->pos())); if (res == idToggleBookmark) { line->toggleBookmark(); doc->tagLines(cursorOnLine, cursorOnLine); doc->updateViews(); } else if (res == idToggleBreakpoint) emit myView->toggledBreakpoint(cursorOnLine); else if (res == idEditBreakpoint) |