From 4f81256efb4843c6831a9d438d787ae5723a20e7 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 5 May 2007 23:03:16 +0200 Subject: [PATCH] Remove the now unused classes TextView and TableView. --- kdbg/Makefile.am | 4 - kdbg/tableview.cpp | 403 ----------------------------------------------------- kdbg/tableview.h | 76 ---------- kdbg/textvw.cpp | 394 --------------------------------------------------- kdbg/textvw.h | 61 -------- 5 files changed, 938 deletions(-) delete mode 100644 kdbg/tableview.cpp delete mode 100644 kdbg/tableview.h delete mode 100644 kdbg/textvw.cpp delete mode 100644 kdbg/textvw.h diff --git a/kdbg/Makefile.am b/kdbg/Makefile.am index 1bb4793..763ec0a 100644 --- a/kdbg/Makefile.am +++ b/kdbg/Makefile.am @@ -16,8 +16,6 @@ kdbg_SOURCES = \ pgmargsbase.ui \ procattach.cpp \ procattachbase.ui \ - tableview.cpp \ - textvw.cpp \ debugger.cpp \ programconfig.cpp \ dbgdriver.cpp \ @@ -50,8 +48,6 @@ kdbg_LDADD = $(LIB_KIO) noinst_HEADERS = \ pgmargs.h \ procattach.h \ - tableview.h \ - textvw.h \ valarray.h \ debugger.h \ programconfig.h \ diff --git a/kdbg/tableview.cpp b/kdbg/tableview.cpp deleted file mode 100644 index 6b7c4cb..0000000 --- a/kdbg/tableview.cpp +++ /dev/null @@ -1,403 +0,0 @@ -// $Id$ - -// Copyright by Johannes Sixt -// This file is under GPL, the GNU General Public Licence - -#include "tableview.h" - -#include -#include -#include - -#if 0 -class CornerSquare : public QWidget // internal class -{ -public: - CornerSquare(QWidget* parent, const char* name = 0); - void paintEvent(QPaintEvent*); -}; - -CornerSquare::CornerSquare(QWidget* parent, const char* name) : - QWidget(parent, name) -{ -} - -void CornerSquare::paintEvent(QPaintEvent*) -{ -} -#endif - -/* - * A simplified version of QTableView, which works only for rows of uniform - * height: cellHeight() is only invoked for row 0. - */ -TableView::TableView(QWidget* parent, const char* name, WFlags f) : - QWidget(parent, name, f), - m_numRows(0), - m_numCols(0), - m_xOffset(0), - m_yOffset(0), - m_totalSize(0, 0), - m_autoUpdate(true) -{ - m_sbV = new QScrollBar(QScrollBar::Vertical, this, "table_sbV"); - m_sbH = new QScrollBar(QScrollBar::Horizontal, this, "table_sbH"); - m_sbV->resize(m_sbV->sizeHint()); - m_sbH->resize(m_sbH->sizeHint()); - m_sbV->hide(); - m_sbH->hide(); - connect(m_sbV, SIGNAL(valueChanged(int)), this, SLOT(sbVer(int))); - connect(m_sbH, SIGNAL(valueChanged(int)), this, SLOT(sbHor(int))); - - m_sbCorner = new QWidget(this, "table_corner"); - m_sbCorner->hide(); - - setFocusPolicy(WheelFocus); -} - -TableView::~TableView() -{ -} - -void TableView::setNumCols(int cols) -{ - m_numCols = cols; -} - -void TableView::setNumRows(int rows) -{ - m_numRows = rows; -} - -void TableView::updateTableSize() -{ - // don't call cellHeight if there are now rows - m_totalSize.setHeight(m_numRows > 0 ? cellHeight(0) * m_numRows : 0); - int w = 0; - for (int i = 0; i < m_numCols; i++) { - w += cellWidth(i); - } - m_totalSize.setWidth(w); - int maxX = maxXOffset(); - int maxY = maxYOffset(); - if (xOffset() > maxX || yOffset() > maxY) { - setOffset(QMIN(xOffset(),maxX), QMIN(yOffset(),maxY)); - } else { - updateScrollBars(); - } -} - -int TableView::lastRowVisible() const -{ - if (numRows() == 0) - return -1; - int r = (viewHeight() + m_yOffset) / cellHeight(0) - 1; - if (r < 0) { - return 0; - } else if (r >= numRows()) { - return numRows()-1; - } else { - return r; - } -} - -int TableView::maxXOffset() const -{ - int o = m_totalSize.width()-viewWidth(); - return QMAX(0, o); -} - -int TableView::maxYOffset() const -{ - int o = m_totalSize.height()-viewHeight(); - return QMAX(0, o); -} - -void TableView::setOffset(int x, int y) -{ - int oldX = m_xOffset; - int oldY = m_yOffset; - int maxX = maxXOffset(); - int maxY = maxYOffset(); - m_xOffset = QMIN(x, maxX); - m_yOffset = QMIN(y, maxY); - if (m_autoUpdate) { - QRect r(0,0, viewWidth(), viewHeight()); - scroll(oldX-m_xOffset, oldY-m_yOffset, r); - } - updateScrollBars(); -} - -void TableView::setTopCell(int row) -{ - if (numRows() > 0) - setYOffset(row * cellHeight(0)); -} - -int TableView::topCell() const -{ - if (numRows() > 0) - return yOffset() / cellHeight(0); - else - return -1; -} - -int TableView::leftCell() const -{ - int x = -xOffset(); - int c = 0; - while (x < 0) { - x += cellWidth(c); - c++; - } - // special-casing x == 0 saves one call to cellWidth() - return x == 0 ? c : c-1; -} - -int TableView::viewWidth() const -{ - // takes into account whether scrollbars are visible - int w = width(); - if (m_sbV->isVisible()) - w -= m_sbV->width(); - return w; -} - -int TableView::viewHeight() const -{ - // takes into account whether scrollbars are visible - int h = height(); - if (m_sbH->isVisible()) - h -= m_sbH->height(); - return h; -} - -bool TableView::rowIsVisible(int row) const -{ - return row >= topCell() && row <= lastRowVisible(); -} - -int TableView::findRow(int y) const -{ - if (numRows() == 0) - return -1; - int r = (yOffset() + y) / cellHeight(0); - if (r < 0 || r >= numRows()) - return -1; - else - return r; -} - -bool TableView::rowYPos(int row, int* top) const -{ - if (numRows() == 0) - return false; // now rows => nothing visible - int y = row * cellHeight(0) - yOffset(); - if (y <= -cellHeight(0)) - return false; // row is above view - if (y > viewHeight()) - return false; // row is below view - *top = y; - return true; -} - -int TableView::findCol(int x) const -{ - x += xOffset(); - if (x < 0) - return -1; - for (int col = 0; col < numCols(); col++) { - x -= cellWidth(col); - if (x < 0) - return col; - } - return -1; -} - -bool TableView::colXPos(int col, int* left) const -{ - int x = -xOffset(); - int viewW = viewWidth(); - int c = 0; - while (c < col) { - x += cellWidth(c); - if (x >= viewW) { - // col is completely to the right of view - return false; - } - c++; - } - if (x <= 0) { - if (x + cellWidth(col) > 0) { - // col is partially visible at left of view - *left = x; - return true; - } else { - // col is completely to the left of view - return false; - } - } else { - // left edge of col is in the view - *left = x; - return true; - } -} - -void TableView::updateCell(int row, int col, bool erase) -{ - int x, y; - if (!colXPos(col, &x)) - return; - if (!rowYPos(row, &y)) - return; - QRect r(x, y, cellWidth(col), cellHeight(0/*row*/)); - repaint(r, erase); -} - -void TableView::setupPainter(QPainter* /*p*/) -{ - // does nothing special -} - -void TableView::resizeEvent(QResizeEvent* /*ev*/) -{ - updateScrollBars(); -} - -void TableView::paintEvent(QPaintEvent* /*ev*/) -{ - if (numRows() == 0 || numCols() == 0) - return; - - QPainter p(this); - setupPainter(&p); - - int viewH = viewHeight(); - int viewW = viewWidth(); - int leftCol = leftCell(); - int leftX = 0; - colXPos(leftCol, &leftX); - int row = topCell(); - int y = 0; - rowYPos(row, &y); - QWMatrix matrix; - while (y < viewH && row < numRows()) { - int col = leftCol; - int x = leftX; - while (x < viewW && col < numCols()) { - matrix.translate(x, y); - p.setWorldMatrix(matrix); - paintCell(&p, row, col); - matrix.reset(); - p.setWorldMatrix(matrix); - x += cellWidth(col); - col++; - } - row++; - y += cellHeight(0/*row*/); - } -} - -void TableView::wheelEvent(QWheelEvent* ev) -{ -#if QT_VERSION >= 300 - if (ev->orientation() == Horizontal && m_sbH != 0) - { - QApplication::sendEvent(m_sbH, ev); - } - else -#endif - { - if (m_sbV != 0) - { - QApplication::sendEvent(m_sbV, ev); - } - } -} - -void TableView::updateScrollBars() -{ - // see which scrollbars we absolutely need - int w = width(); - int h = height(); - bool needV = m_totalSize.height() > h; - bool needH = m_totalSize.width() > w; - - // if we need neither, remove the scrollbars and we're done - if (!needV && !needH) - { - m_sbH->hide(); - m_sbV->hide(); - m_sbCorner->hide(); - return; - } - // if we need both, reduce view - if (needV && needH) { - w -= m_sbV->width(); - h -= m_sbH->height(); - } else { - /* - * If we need the vertical bar, but not the horizontal, the - * presence of the vertical bar might reduce the space so that we - * also need the horizontal bar. Likewise, if we need the - * horizontal but not necessarily the vertical bar. - */ - if (needV) { - w -= m_sbV->width(); - if (w < 0) - w = 0; - needH = m_totalSize.width() > w; - if (needH) { - h -= m_sbH->height(); - } - } else { - // assert(needH) - h -= m_sbH->height(); - if (h < 0) - h = 0; - needV = m_totalSize.height() > h; - if (needV) { - w -= m_sbV->width(); - } - } - } - // set scrollbars - // note: must show() early because max?Offset() depends on visibility - if (needH) { - m_sbH->setGeometry(0, h, w, m_sbH->height()); - m_sbH->show(); - m_sbH->setRange(0, maxXOffset()); - m_sbH->setValue(xOffset()); - m_sbH->setSteps(32, w); - } else { - m_sbH->hide(); - } - if (needV) { - m_sbV->setGeometry(w, 0, m_sbV->width(), h); - m_sbV->show(); - m_sbV->setRange(0, maxYOffset()); - m_sbV->setValue(yOffset()); - m_sbV->setSteps(cellHeight(0), h); - } else { - m_sbV->hide(); - } - // corner square: only if both scrollbars are there - if (needH && needV) { - m_sbCorner->setGeometry(w, h, m_sbV->width(), m_sbH->height()); - m_sbCorner->show(); - } else { - m_sbCorner->hide(); - } -} - -void TableView::sbVer(int value) -{ - setYOffset(value); -} - -void TableView::sbHor(int value) -{ - setXOffset(value); -} - -#include "tableview.moc" diff --git a/kdbg/tableview.h b/kdbg/tableview.h deleted file mode 100644 index 2757d39..0000000 --- a/kdbg/tableview.h +++ /dev/null @@ -1,76 +0,0 @@ -// $Id$ - -// Copyright by Johannes Sixt -// This file is under GPL, the GNU General Public Licence - -#ifndef TABLEVIEW_H -#define TABLEVIEW_H - -#include - -class QScrollBar; - -class TableView : public QWidget -{ - Q_OBJECT -public: - TableView(QWidget* parent, const char* name, WFlags f); - ~TableView(); - - void setNumCols(int cols); - int numCols() const { return m_numCols; } - void setNumRows(int rows); - int numRows() const { return m_numRows; } - void setAutoUpdate(bool update) { m_autoUpdate = update; } - bool autoUpdate() const { return m_autoUpdate; } - void updateTableSize(); - int totalWidth() const { return m_totalSize.width(); } - int totalHeight() const { return m_totalSize.height(); } - int lastRowVisible() const; - void setTopCell(int row); - int topCell() const; - int leftCell() const; - void setXOffset(int x) { setOffset(x, yOffset()); } - int xOffset() const { return m_xOffset; } - int maxXOffset() const; - void setYOffset(int y) { setOffset(xOffset(), y); } - int yOffset() const { return m_yOffset; } - int maxYOffset() const; - void setOffset(int x, int y); - int viewWidth() const; - int viewHeight() const; - bool rowIsVisible(int row) const; - int findRow(int y) const; - bool rowYPos(int row, int* top) const; - int findCol(int x) const; - bool colXPos(int col, int* left) const; - void updateCell(int row, int col, bool erase = true); - - // override in derived classes - virtual int cellWidth(int col) const = 0; - virtual int cellHeight(int row) const = 0; - virtual void paintCell(QPainter* p, int row, int col) = 0; - virtual void setupPainter(QPainter* p); - -protected: - // overrides - virtual void resizeEvent(QResizeEvent* ev); - virtual void paintEvent(QPaintEvent* ev); - virtual void wheelEvent(QWheelEvent* ev); - -public slots: - void sbVer(int value); - void sbHor(int value); - -private: - int m_numRows, m_numCols; - int m_xOffset, m_yOffset; - QSize m_totalSize; - bool m_autoUpdate; - QScrollBar* m_sbV; - QScrollBar* m_sbH; - QWidget* m_sbCorner; - void updateScrollBars(); -}; - -#endif // TABLEVIEW_H diff --git a/kdbg/textvw.cpp b/kdbg/textvw.cpp deleted file mode 100644 index e2310df..0000000 --- a/kdbg/textvw.cpp +++ /dev/null @@ -1,394 +0,0 @@ -// $Id$ - -// Copyright by Johannes Sixt -// This file is under GPL, the GNU General Public Licence - -#include -#include -#include "textvw.h" -#include "textvw.moc" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include "mydebug.h" -#include - -#define DEFAULT_WIDTH 100 -#define DEFAULT_LINEHEIGHT 1 - -KTextView::KTextView(QWidget* parent, const char* name, WFlags f) : - TableView(parent, name, f), - m_width(DEFAULT_WIDTH), - m_height(DEFAULT_LINEHEIGHT), - m_tabWidth(0), - m_curRow(-1) -{ - setNumCols(1); - setBackgroundColor(colorGroup().base()); -} - -KTextView::~KTextView() -{ -} - -/* - * Update cell width and hight; returns whether there is a change - * Cell geometry: There are 2 pixels to the left and to the right - * and 1 pixel _below_ the line - */ -bool KTextView::updateCellSize(const QString& text) -{ - QPainter p(this); - setupPainter(&p); - QRect r = p.boundingRect(0,0, 0,0, - AlignLeft | SingleLine | DontClip | ExpandTabs, - text, text.length()); - - bool update = false; - int w = r.width() + 4; - if (w > m_width) { - m_width = w; - update = true; - } - int h = r.height() + 1; - if (h > m_height) { - m_height = h; - update = true; - } - return update; -} - -void KTextView::setText(const QString& text) -{ - QStringList l = QStringList::split('\n', text, true); - - bool autoU = autoUpdate(); - setAutoUpdate(false); - - int lineNo = QMIN(m_texts.size(), l.size()); - for (int i = 0; i < lineNo; i++) { - replaceLine(i, l[i]); - } - if (l.size() > m_texts.size()) { - // the new text has more lines than the old one - // here lineNo is the number of lines of the old text - for (size_t i = lineNo; i < l.size(); i++) { - insertLine(l[i]); - } - } else { - // the new file has fewer lines - // here lineNo is the number of lines of the new file - // remove the excessive lines - m_texts.resize(lineNo); - setNumRows(lineNo); - } - - setAutoUpdate(autoU); - if (autoU) { - updateTableSize(); - update(); - } - - // if the cursor is in the deleted lines, move it to the last line - if (m_curRow >= int(m_texts.size())) { - m_curRow = -1; /* at this point don't have an active row */ - activateLine(m_texts.size()-1); /* now we have */ - } -} - -void KTextView::insertLine(const QString& text) -{ - m_texts.push_back(text); - setNumRows(m_texts.size()); - - updateCellSize(text); - - if (autoUpdate()) { - updateTableSize(); - repaint(); - } -} - -/* - * TODO: This function doesn't shrink the line length if the longest line - * is replaced by a shorter one. - */ -void KTextView::replaceLine(int line, const QString& text) -{ - if (line < 0 || line >= int(m_texts.size())) - return; - - m_texts[line] = text; - - bool update = updateCellSize(text); - - if (autoUpdate()) { - if (update) { - updateTableSize(); - } - repaint(); - } -} - -void KTextView::insertParagraph(const QString& text, int row) -{ - m_texts.insert(m_texts.begin()+row, text); - - // update line widths - updateCellSize(text); - - setNumRows(m_texts.size()); - - if (autoUpdate() && isVisible()) { - updateTableSize(); - update(); - } -} - -void KTextView::removeParagraph(int row) -{ - m_texts.erase(m_texts.begin()+row); - setNumRows(m_texts.size()); - - if (autoUpdate() && isVisible()) { - updateTableSize(); - update(); - } -} - -void KTextView::setCursorPosition(int row, int) -{ - activateLine(row); -} - -void KTextView::cursorPosition(int* row, int* col) -{ - *row = m_curRow; - *col = 0; -} - -int KTextView::cellWidth(int /*col*/) const -{ - return m_width; -} - -int KTextView::cellHeight(int /*row*/) const -{ - return m_height; -} - -int KTextView::textCol() const -{ - // by default, the text is in column 0 - return 0; -} - -void KTextView::paintCell(QPainter* p, int row, int /*col*/) -{ - if (row >= int(m_texts.size())) { - return; - } - if (row == m_curRow) { - // paint background - p->fillRect(0,0, m_width,m_height, QBrush(colorGroup().background())); - } - const QString& text = m_texts[row]; - p->drawText(2,0, m_width-4, m_height, - AlignLeft | SingleLine | DontClip | ExpandTabs, - text, text.length()); -} - -void KTextView::keyPressEvent(QKeyEvent* ev) -{ - int oldRow = m_curRow; - - // go to line 0 if no current line - if (m_curRow < 0) { - activateLine(0); - } - else - { - int numVisibleRows, newRow, newX; - - switch (ev->key()) { - case Key_Up: - if (m_curRow > 0) { - activateLine(m_curRow-1); - } - break; - case Key_Down: - if (m_curRow < numRows()-1) { - activateLine(m_curRow+1); - } - break; - case Key_PageUp: - /* this method doesn't work for variable height lines */ - numVisibleRows = lastRowVisible()-topCell(); - newRow = m_curRow - QMAX(numVisibleRows,1); - if (newRow < 0) - newRow = 0; - activateLine(newRow); - break; - case Key_PageDown: - /* this method doesn't work for variable height lines */ - numVisibleRows = lastRowVisible()-topCell(); - newRow = m_curRow + QMAX(numVisibleRows,1); - if (newRow >= numRows()) - newRow = numRows()-1; - activateLine(newRow); - break; - - // scroll left and right by a few pixels - case Key_Left: - newX = xOffset() - viewWidth()/10; - setXOffset(QMAX(newX, 0)); - break; - case Key_Right: - newX = xOffset() + viewWidth()/10; - setXOffset(QMIN(newX, maxXOffset())); - break; - - default: - QWidget::keyPressEvent(ev); - return; - } - } - // make row visible - if (m_curRow != oldRow && !rowIsVisible(m_curRow)) { - // if the old row was visible, we scroll the view by some pixels - // if the old row was not visible, we place active row at the top - if (oldRow >= 0 && rowIsVisible(oldRow)) { - int diff = m_curRow - oldRow; - int newTop = topCell() + diff; - setTopCell(QMAX(newTop,0)); - } else { - setTopCell(m_curRow); - } - } - ev->accept(); -} - -void KTextView::mousePressEvent(QMouseEvent* ev) -{ - int row = findRow(ev->y()); - activateLine(row); -} - -void KTextView::focusInEvent(QFocusEvent*) -{ - /* - * The base class does a repaint(), which causes flicker. So we do - * nothing here. - */ -} - -void KTextView::focusOutEvent(QFocusEvent*) -{ - /* - * The base class does a repaint(), which causes flicker. So we do - * nothing here. - */ -} - -void KTextView::activateLine(int row) -{ - if (row == m_curRow) - return; - - int col = textCol(); - - int oldRow = m_curRow; - // note that row may be < 0 - m_curRow = row; - // must change m_curRow first, so that updateCell(oldRow) erases the old line! - if (oldRow >= 0) { - updateCell(oldRow, col); - } - if (row >= 0) { - updateCell(row, col); - } - emit lineChanged(); -} - -/* This is needed to make the kcontrol's color setup working */ -void KTextView::paletteChange(const QPalette& oldPal) -{ - setBackgroundColor(colorGroup().base()); - TableView::paletteChange(oldPal); - - // recompute window size - m_width = DEFAULT_WIDTH; - m_height = DEFAULT_LINEHEIGHT; - for (size_t i = 0; i < m_texts.size(); i++) { - updateCellSize(m_texts[i]); - } - updateTableSize(); -} - -void KTextView::setTabWidth(int numChars) -{ - QFontMetrics fm = font(); - int newTabWidth = fm.width('x') * numChars; - if (newTabWidth == m_tabWidth) - return; - m_tabWidth = newTabWidth; - - // recompute window width - m_width = DEFAULT_WIDTH; - for (size_t i = 0; i < m_texts.size(); i++) { - updateCellSize(m_texts[i]); - } - - updateTableSize(); - if (autoUpdate()) { - repaint(); - } -} - -void KTextView::setupPainter(QPainter* p) -{ - p->setTabStops(m_tabWidth); -} - -int KTextView::charAt(const QPoint& p, int* para) -{ - if (findCol(p.x()) != textCol()) - return *para = -1; - int row = findRow(p.y()); - *para = row; - if (row < 0) - return -1; - - // find top-left corner of text cell - int top, left; - if (!colXPos(textCol(), &left)) - return -1; - if (!rowYPos(row, &top)) - return -1; - - // get the bounding rect of the text - QPainter painter(this); - setupPainter(&painter); - const QString& text = m_texts[row]; - QRect bound = - painter.boundingRect(left+2, top, 0,0, - AlignLeft | SingleLine | DontClip | ExpandTabs, - text, text.length()); - if (!bound.contains(p)) - return -1; /* p is outside text */ - - for (uint n = 0; n < text.length(); n++) - { - /* - * If p is in the rectangle that has n+1 characters, than n - * is the character we are looking for - */ - bound = - painter.boundingRect(left+2, top, 0,0, - AlignLeft | SingleLine | DontClip | ExpandTabs, - text, n+1); - if (bound.contains(p)) - return n; - } - return -1; -} diff --git a/kdbg/textvw.h b/kdbg/textvw.h deleted file mode 100644 index f992022..0000000 --- a/kdbg/textvw.h +++ /dev/null @@ -1,61 +0,0 @@ -// $Id$ - -// Copyright by Johannes Sixt -// This file is under GPL, the GNU General Public Licence - -#ifndef TEXTVW_H -#define TEXTVW_H - -#include "tableview.h" -#include - -class KTextView : public TableView -{ - Q_OBJECT -public: - KTextView(QWidget* parent = 0, const char* name = 0, WFlags f = 0); - ~KTextView(); - void insertLine(const QString& text); - void replaceLine(int line, const QString& text); - virtual void setCursorPosition(int row, int col); - virtual void cursorPosition(int* row, int* col); - void setText(const QString& t); - const QString& text(int i) const { return m_texts[i]; } - int paragraphs() const { return m_texts.size(); } - void insertParagraph(const QString& text, int row); - void removeParagraph(int row); - int charAt(const QPoint& p, int* para); -protected: - virtual int cellWidth(int col) const; - virtual int cellHeight(int row) const; - virtual void paintCell(QPainter* p, int row, int col); - virtual void activateLine(int row); - virtual int textCol() const; - virtual bool updateCellSize(const QString& text); - virtual void setupPainter(QPainter* p); - -signals: - void lineChanged(); - -public slots: - void setTabWidth(int numChars); - - // event handling -protected: - virtual void keyPressEvent(QKeyEvent* ev); - virtual void mousePressEvent(QMouseEvent* ev); - virtual void focusInEvent(QFocusEvent* ev); - virtual void focusOutEvent(QFocusEvent* ev); - - void paletteChange(const QPalette& oldPal); - - int m_width; - int m_height; /* line height */ - int m_tabWidth; /* in pixels */ - - int m_curRow; /* cursor position */ -private: - std::vector m_texts; -}; - -#endif // TEXTVW_H -- 2.11.4.GIT