1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
/***************************************************************************
** xMultiLineFrame.cpp $Revision: 1.7 $ - $Name: V2-18 $
** QFrame for manipulating Multiple lines of text in a window
**
** Copyright (C) 1996 Joseph Croft <jcroft@unicomp.net>
**
** 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; if not, write to the Free
** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
***************************************************************************/
#include <stdio.h>
#include "xMultiLineFrame.h"
static int dbg = 0;
xMultiLineFrame::xMultiLineFrame(xWidgetResInfo *pPRes, QWidget *pParent,
const char *pName,
int width, int height,
int maxLines) :
QFrame(pParent, pName)
{
QRect rectWin;
wdtRes = new xWidgetResInfo(pPRes, QString("multiline.frame"), QString("MultiLine.Frame"));
wdtPrv = new xWidgetResInfo(pPRes);
setDefPallet(this, wdtRes);
setDefFont(this, wdtRes);
setLineWidth(3);
setFrameStyle(QFrame::Panel | QFrame::Sunken);
pScrollBar = new xVertScrollBar(wdtRes, this);
pScrollBar->setTracking(TRUE);
pWin = new xMultiLineWin(wdtPrv, this, NULL, width, height, maxLines);
connect(pWin, SIGNAL(textSelected(QString)),
this, SLOT(haveTextSelection(QString)));
QFontMetrics fmWin = pWin->fontMetrics();
widthSB = (int)((float)fmWin.maxWidth() * 2.0);
rectWin = pWin->geometry();
pWin->move(widthSB, 0);
pScrollBar->setGeometry(0, 0, widthSB, (pWin->geometry()).height());
setSizeIncrement(fmWin.maxWidth(), fmWin.lineSpacing());
setMinimumSize(fmWin.maxWidth() * 10, fmWin.lineSpacing() * 3);
rectWin.setRight(rectWin.right() + widthSB);
setGeometry(rectWin);
connect(pWin, SIGNAL(changePageSize(int)), this, SLOT(changePageStep(int)));
connect(pWin, SIGNAL(linesUsedChanged(int)), this, SLOT(changeSBRange(int)));
connect(pScrollBar, SIGNAL(prevPage()), this, SLOT(gotoPrevPage()));
connect(pScrollBar, SIGNAL(nextPage()), this, SLOT(gotoNextPage()));
connect(pScrollBar, SIGNAL(prevLine()), this, SLOT(gotoPrevLine()));
connect(pScrollBar, SIGNAL(nextLine()), this, SLOT(gotoNextLine()));
connect(pScrollBar, SIGNAL(sliderMoved(int)), this, SLOT(gotoOffset(int)));
changePageStep(height);
}
xMultiLineFrame::~xMultiLineFrame()
{
if (pWin)
delete pWin;
if (pScrollBar)
delete pScrollBar;
}
/*
void xMultiLineFrame::reset()
{
pWin->reset();
}
*/
void xMultiLineFrame::resizeEvent(QResizeEvent *pEvt)
{
QSize s, sizeTW, sizeNewTW, sizeSB;
sizeSB = sizeTW = pEvt->size();
sizeTW.setWidth(sizeTW.width() - widthSB);
pWin->resize(sizeTW);
sizeNewTW = pWin->size();
if (sizeTW != sizeNewTW)
{
s = sizeNewTW;
s.setWidth(sizeNewTW.width() + widthSB);
resize(s);
}
sizeSB.setWidth(widthSB);
sizeSB.setHeight(pWin->size().height());
pScrollBar->resize(sizeSB);
}
void xMultiLineFrame::changeSBRange(int linesUsed)
{
if (dbg) fprintf(stdout, "xMultiLineFrame::changeLinesUsed(%d)\n", linesUsed);
if (dbg) fprintf(stdout, "xMultiLineFrame::changeLinesUsed():linesUsed = %d, pageStep = %d\n", linesUsed, (int)pScrollBar->pageStep());
if (linesUsed > pScrollBar->pageStep())
{
if (dbg) fprintf(stdout, "xMultiLineFrame::changeLinesUsed():Showing Scroll Bar:linesUsed = %d, pageStep = %d\n", linesUsed, (int)pScrollBar->pageStep());
pScrollBar->show();
pScrollBar->setRange(0, linesUsed - pScrollBar->pageStep());
pScrollBar->setValue(pWin->getPosition() - pScrollBar->pageStep() + 1);
}
else
{
if (dbg) fprintf(stdout, "xMultiLineFrame::changeLinesUsed):Hiding Scroll Bar:linesUsed = %d, pageStep = %d\n", linesUsed, (int)pScrollBar->pageStep());
pScrollBar->setRange(0, 0);
pScrollBar->show();
}
}
void xMultiLineFrame::changePageStep(int pageLength)
{
if (dbg) fprintf(stdout, "xMultiLineFrame::changePageStep(%d):Enter\n", pageLength);
if (dbg) fprintf(stdout, "xMultiLineFrame::changePageStep():linesUsed = %d\n", pWin->getLinesUsed());
pScrollBar->setSteps(1, pageLength);
if (pScrollBar->pageStep() > pWin->getLinesUsed())
{
pScrollBar->setRange(0, 0);
pScrollBar->show();
}
else
{
pScrollBar->setRange(0, pWin->getLinesUsed() - pScrollBar->pageStep());
pScrollBar->setValue(pWin->getPosition() - pScrollBar->pageStep() + 1);
pScrollBar->show();
}
}
void xMultiLineFrame::gotoOffset(int offset)
{
if (dbg) fprintf(stdout, "xMultiLineFrame::gotoOffset():offset = %d\n", offset);
if (dbg) fflush(stdout);
pWin->scrollToLine(offset);
if (dbg) fprintf(stdout, "xMultiLineFrame::gotoOffset():Exit\n");
if (dbg) fflush(stdout);
}
void xMultiLineFrame::gotoPrevPage()
{
pWin->scrollWindow(-(pScrollBar->pageStep()));
}
void xMultiLineFrame::gotoNextPage()
{
pWin->scrollWindow(pScrollBar->pageStep());
}
void xMultiLineFrame::gotoPrevLine()
{
pWin->scrollWindow(-1);
}
void xMultiLineFrame::gotoNextLine()
{
pWin->scrollWindow(1);
}
void xMultiLineFrame::haveTextSelection(QString str)
{
xMultiLineTextSelection msg;
if (name() == NULL || strlen(name()) == 0)
msg.winName = parent()->name();
else
msg.winName = name();
msg.text = str;
emit textSelected(msg);
}
xVertScrollBar::xVertScrollBar(xWidgetResInfo *pPRes, QWidget *pParent = NULL,
const char *pName = NULL) :
QScrollBar(QScrollBar::Vertical, pParent, pName)
{
wdtRes = new xWidgetResInfo(pPRes, QString("scrollbar"), QString("ScrollBar"));
setRange(0, 0);
setSteps(1, 1);
}
// void xMultiLineFrame::mouseDoubleClickEvent(QMouseEvent *pEvt)
// {
// pWin->mouseDoubleClickEvent(pEvt);
// }
#include "xMultiLineFrame.moc"
|