diff --git a/src/canvas.cpp b/src/canvas.cpp index f5a27ea5..11f13a1e 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -1,1443 +1,1443 @@ /*************************************************************************** * Copyright (C) 1999-2005 Trolltech AS * * Copyright (C) 2006 David Saxton * * * * This file may be distributed and/or modified under the terms of the * * GNU General Public License version 2 as published by the Free * * Software Foundation * ***************************************************************************/ #include "utils.h" #include "canvas.h" #include "canvas_private.h" #include #include "qapplication.h" #include "qbitmap.h" //#include "q3ptrdict.h" #include "qpainter.h" #include "ktlq3polygonscanner.h" #include "qtimer.h" // #include "q3tl.h" // #include // needed for q3polygonscanner -#include +#include #include #include using namespace std; static bool isCanvasDebugEnabled() { return false; } //BEGIN class KtlQCanvasClusterizer static void include(QRect& r, const QRect& rect) { if (rect.left()r.right()) { r.setRight(rect.right()); } if (rect.top()r.bottom()) { r.setBottom(rect.bottom()); } } /* A KtlQCanvasClusterizer groups rectangles (QRects) into non-overlapping rectangles by a merging heuristic. */ KtlQCanvasClusterizer::KtlQCanvasClusterizer(int maxclusters) : cluster(new QRect[maxclusters]), count(0), maxcl(maxclusters) { } KtlQCanvasClusterizer::~KtlQCanvasClusterizer() { delete [] cluster; } void KtlQCanvasClusterizer::clear() { count=0; } void KtlQCanvasClusterizer::add(int x, int y) { add(QRect(x,y,1,1)); } void KtlQCanvasClusterizer::add(int x, int y, int w, int h) { add(QRect(x,y,w,h)); } void KtlQCanvasClusterizer::add(const QRect& rect) { QRect biggerrect(rect.x()-1,rect.y()-1,rect.width()+2,rect.height()+2); //assert(rect.width()>0 && rect.height()>0); int cursor; for (cursor=0; cursor=0) { include(cluster[cheapest],rect); return; } if (count < maxcl) { cluster[count++]=rect; return; } // Do cheapest of: // add to closest cluster // do cheapest cluster merge, add to new cluster lowestcost=9999999; cheapest=-1; cursor=0; while( cursor=0) { include(cluster[cheapestmerge1],cluster[cheapestmerge2]); cluster[cheapestmerge2]=cluster[count--]; } else { // if (!cheapest) debugRectangles(rect); include(cluster[cheapest],rect); } // NB: clusters do not intersect (or intersection will // overwrite). This is a result of the above algorithm, // given the assumption that (x,y) are ordered topleft // to bottomright. // ### // // add explicit x/y ordering to that comment, move it to the top // and rephrase it as pre-/post-conditions. } const QRect& KtlQCanvasClusterizer::operator[](int i) { return cluster[i]; } //END class KtlQCanvasClusterizer static int gcd(int a, int b) { int r; while ( (r = a%b) ) { a=b; b=r; } return b; } static int scm(int a, int b) { int g = gcd(a,b); return a/g*b; } int KtlQCanvas::toChunkScaling( int x ) const { return roundDown( x, chunksize ); } void KtlQCanvas::initChunkSize( const QRect & s ) { m_chunkSize = QRect( toChunkScaling(s.left()), toChunkScaling(s.top()), ((s.width()-1)/chunksize)+3, ((s.height()-1)/chunksize)+3 ); } void KtlQCanvas::init(int w, int h, int chunksze, int mxclusters) { init( QRect( 0, 0, w, h ), chunksze, mxclusters ); } void KtlQCanvas::init( const QRect & r, int chunksze, int mxclusters ) { m_size = r ; chunksize=chunksze; maxclusters=mxclusters; initChunkSize( r ); chunks=new KtlQCanvasChunk[m_chunkSize.width()*m_chunkSize.height()]; update_timer = 0; bgcolor = Qt::white; grid = 0; htiles = 0; vtiles = 0; debug_redraw_areas = false; } KtlQCanvas::KtlQCanvas( QObject* parent, const char* name ) : QObject( parent /*, name*/ ) { setObjectName( name ); init(0,0); } KtlQCanvas::KtlQCanvas(const int w, const int h) { init(w,h); } KtlQCanvas::KtlQCanvas( QPixmap p, int h, int v, int tilewidth, int tileheight ) { init(h*tilewidth, v*tileheight, scm(tilewidth,tileheight) ); setTiles( p, h, v, tilewidth, tileheight ); } void qt_unview( KtlQCanvas * c ) { for (QList::iterator itView =c->m_viewList.begin(); itView != c->m_viewList.end(); ++itView) { KtlQCanvasView* view = *itView; view->viewing = 0; } } KtlQCanvas::~KtlQCanvas() { qt_unview(this); KtlQCanvasItemList all = allItems(); for (KtlQCanvasItemList::Iterator it=all.begin(); it!=all.end(); ++it) delete *it; delete [] chunks; delete [] grid; } /*! \internal Returns the chunk at a chunk position \a i, \a j. */ KtlQCanvasChunk& KtlQCanvas::chunk(int i, int j) const { i -= m_chunkSize.left(); j -= m_chunkSize.top(); //return chunks[i+m_chunkSize.width()*j]; const int chunkOffset = i + m_chunkSize.width() * j; if ((chunkOffset < 0) || (chunkOffset >= (m_chunkSize.width()*m_chunkSize.height())) ) { qWarning() << Q_FUNC_INFO << " invalid chunk coordinates: " << i << " " << j; return chunks[0]; // at least it should not crash } return chunks[chunkOffset]; } /*! \internal Returns the chunk at a pixel position \a x, \a y. */ KtlQCanvasChunk& KtlQCanvas::chunkContaining(int x, int y) const { return chunk( toChunkScaling(x), toChunkScaling(y) ); } KtlQCanvasItemList KtlQCanvas::allItems() { KtlQCanvasItemList list; SortedCanvasItems::iterator end = m_canvasItems.end(); for ( SortedCanvasItems::iterator it = m_canvasItems.begin(); it != end; ++it ) list << it->second; return list; } void KtlQCanvas::resize( const QRect & newSize ) { if ( newSize == m_size ) return; KtlQCanvasItem* item; QList hidden; SortedCanvasItems::iterator end = m_canvasItems.end(); for ( SortedCanvasItems::iterator it = m_canvasItems.begin(); it != end; ++it ) { KtlQCanvasItem * i = it->second; if ( i->isVisible() ) { i->hide(); hidden.append( i ); } } initChunkSize( newSize ); KtlQCanvasChunk* newchunks = new KtlQCanvasChunk[m_chunkSize.width()*m_chunkSize.height()]; m_size = newSize; delete [] chunks; chunks=newchunks; for (QList::iterator itItem = hidden.begin(); itItem != hidden.end(); ++itItem) { KtlQCanvasItem* item = *itItem; item->show(); } // for (item=hidden.first(); item != 0; item=hidden.next()) { // 2018.08.14 - use QList // item->show(); // } setAllChanged(); emit resized(); } void KtlQCanvas::retune(int chunksze, int mxclusters) { maxclusters=mxclusters; if ( chunksize!=chunksze ) { QList hidden; SortedCanvasItems::iterator end = m_canvasItems.end(); for ( SortedCanvasItems::iterator it = m_canvasItems.begin(); it != end; ++it ) { KtlQCanvasItem * i = it->second; if ( i->isVisible() ) { i->hide(); hidden.append( i ); } } chunksize=chunksze; initChunkSize( m_size ); KtlQCanvasChunk* newchunks = new KtlQCanvasChunk[m_chunkSize.width()*m_chunkSize.height()]; delete [] chunks; chunks=newchunks; for (QList::iterator itItem = hidden.begin(); itItem != hidden.end(); ++itItem) { KtlQCanvasItem* item = *itItem; item->show(); } } } void KtlQCanvas::addItem(KtlQCanvasItem* item) { m_canvasItems.insert( make_pair( item->z(), item ) ); } void KtlQCanvas::removeItem(const KtlQCanvasItem* item) { SortedCanvasItems::iterator end = m_canvasItems.end(); for ( SortedCanvasItems::iterator it = m_canvasItems.begin(); it != end; ++it ) { if ( it->second == item ) { m_canvasItems.erase( it ); return; } } } void KtlQCanvas::addView(KtlQCanvasView* view) { m_viewList.append(view); if ( htiles>1 || vtiles>1 || pm.isNull() ) { //view->viewport()->setBackgroundColor(backgroundColor()); // 2018.11.21 QPalette palette; palette.setColor(view->viewport()->backgroundRole(), backgroundColor()); view->viewport()->setPalette(palette); } } void KtlQCanvas::removeView(KtlQCanvasView* view) { m_viewList.removeAll(view); } void KtlQCanvas::setUpdatePeriod(int ms) { if ( ms<0 ) { if ( update_timer ) update_timer->stop(); } else { if ( update_timer ) delete update_timer; update_timer = new QTimer(this); connect(update_timer,SIGNAL(timeout()),this,SLOT(update())); update_timer->start(ms); } } // Don't call this unless you know what you're doing. // p is in the content's co-ordinate example. void KtlQCanvas::drawViewArea( KtlQCanvasView* view, QPainter* p, const QRect& vr, bool dbuf /* always false */) { QPoint tl = view->contentsToViewport(QPoint(0,0)); QMatrix wm = view->worldMatrix(); QMatrix iwm = wm.inverted(); // ivr = covers all chunks in vr QRect ivr = iwm.mapRect(vr); QMatrix twm; twm.translate(tl.x(),tl.y()); // QRect all(0,0,width(),height()); QRect all(m_size); if (!p->isActive()) { qWarning() << Q_FUNC_INFO << " painter is not active"; } if ( !all.contains(ivr) ) { // Need to clip with edge of canvas. // For translation-only transformation, it is safe to include the right // and bottom edges, but otherwise, these must be excluded since they // are not precisely defined (different bresenham paths). QPolygon a; if ( wm.m12()==0.0 && wm.m21()==0.0 && wm.m11() == 1.0 && wm.m22() == 1.0 ) a = QPolygon( QRect(all.x(),all.y(),all.width()+1,all.height()+1) ); else a = QPolygon( all ); a = (wm*twm).map(a); //if ( view->viewport()->backgroundMode() == Qt::NoBackground ) // 2018.12.02 QWidget *vp = view->viewport(); if ( vp->palette().color( vp->backgroundRole() ) == QColor(Qt::transparent) ) { QRect cvr = vr; cvr.translate(tl.x(),tl.y()); p->setClipRegion(QRegion(cvr)-QRegion(a)); p->fillRect(vr,view->viewport()->palette() .brush(QPalette::Active,QColorGroup::Background)); } p->setClipRegion(a); } #if 0 // 2018.03.11 - dbuf is always false if ( dbuf ) { offscr = QPixmap(vr.width(), vr.height()); offscr.x11SetScreen(p->device()->x11Screen()); //QPainter dbp(&offscr); QPainter dbp; const bool isSuccess = dbp.begin(&offscr); if (!isSuccess) { qWarning() << Q_FUNC_INFO << " painter not active"; } twm.translate(-vr.x(),-vr.y()); twm.translate(-tl.x(),-tl.y()); dbp.setWorldMatrix( wm*twm, true ); // 2015.11.27 - do not clip, in order to fix drawing of garbage on the screen. //dbp.setClipRect(0,0,vr.width(), vr.height()); // dbp.setClipRect(v); drawCanvasArea(ivr,&dbp,false); dbp.end(); p->drawPixmap(vr.x(), vr.y(), offscr, 0, 0, vr.width(), vr.height()); } else #endif { QRect r = vr; r.translate(tl.x(),tl.y()); // move to untransformed co-ords if ( !all.contains(ivr) ) { QRegion inside = p->clipRegion() & r; //QRegion outside = p->clipRegion() - r; //p->setClipRegion(outside); //p->fillRect(outside.boundingRect(),red); // 2015.11.27 - do not clip, in order to fix drawing of garbage on the screen. //p->setClipRegion(inside); } else { // 2015.11.27 - do not clip, in order to fix drawing of garbage on the screen. //p->setClipRect(r); } p->setWorldMatrix( wm*twm ); p->setBrushOrigin(tl.x(), tl.y()); drawCanvasArea(ivr,p,false); } } void KtlQCanvas::advance() { qWarning() << "KtlQCanvas::advance: TODO"; // TODO } /*! Repaints changed areas in all views of the canvas. */ void KtlQCanvas::update() { KtlQCanvasClusterizer clusterizer(m_viewList.count()); QList doneareas; //Q3PtrListIterator it(m_viewList); // 2018.08.14 - see below //KtlQCanvasView* view; //while( (view=it.current()) != 0 ) { // ++it; // for (QList::iterator itView = m_viewList.begin(); itView != m_viewList.end(); ++itView) { KtlQCanvasView* view = *itView; QMatrix wm = view->worldMatrix(); QRect area(view->contentsX(),view->contentsY(), view->visibleWidth(),view->visibleHeight()); if (area.width()>0 && area.height()>0) { if ( !wm.isIdentity() ) { // r = Visible area of the canvas where there are changes QRect r = changeBounds(view->inverseWorldMatrix().mapRect(area)); if ( !r.isEmpty() ) { // as of my testing, drawing below always fails, so just post for an update event to the widget view->viewport()->update(); #if 0 //view->viewport()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); // note: remove this when possible //QPainter p(view->viewport()); QPainter p; const bool startSucces = p.begin( view->viewport() ); if (!startSucces) { qWarning() << Q_FUNC_INFO << " painter is not active "; } // Translate to the coordinate system of drawViewArea(). QPoint tl = view->contentsToViewport(QPoint(0,0)); p.translate(tl.x(),tl.y()); // drawViewArea( view, &p, wm.map(r), true ); #endif doneareas.append(r); } } else clusterizer.add(area); } } for (int i=0; i::iterator itDone = doneareas.begin(); itDone != doneareas.end(); ++itDone) { setUnchanged( *itDone ); } } /*! Marks the whole canvas as changed. All views of the canvas will be entirely redrawn when update() is called next. */ void KtlQCanvas::setAllChanged() { setChanged(m_size); } /*! Marks \a area as changed. This \a area will be redrawn in all views that are showing it when update() is called next. */ void KtlQCanvas::setChanged(const QRect& area) { QRect thearea = area.intersect( m_size ); int mx = toChunkScaling(thearea.x()+thearea.width()+chunksize); int my = toChunkScaling(thearea.y()+thearea.height()+chunksize); if (mx > m_chunkSize.right()) mx=m_chunkSize.right(); if (my > m_chunkSize.bottom()) my=m_chunkSize.bottom(); int x= toChunkScaling(thearea.x()); while( x m_chunkSize.right()) mx=m_chunkSize.right(); if (my > m_chunkSize.bottom()) my=m_chunkSize.bottom(); int x = toChunkScaling(thearea.x()); while( x m_chunkSize.right()) mx=m_chunkSize.right(); if (my > m_chunkSize.bottom()) my=m_chunkSize.bottom(); QRect result; int x = toChunkScaling(area.x()); while( x m_chunkSize.right()) mx=m_chunkSize.right(); if (my > m_chunkSize.bottom()) my=m_chunkSize.bottom(); int x = toChunkScaling(area.x()); while( x=m_chunkSize.right()) mx=m_chunkSize.right()-1; if (my>=m_chunkSize.bottom()) my=m_chunkSize.bottom()-1; // Stores the region within area that need to be drawn. It is relative // to area.topLeft() (so as to keep within bounds of 16-bit XRegions) QRegion rgn; for (int x=lx; x<=mx; x++) { for (int y=ly; y<=my; y++) { // Only reset change if all views updating, and // wholy within area. (conservative: ignore entire boundary) // // Disable this to help debugging. // if (!p) { if ( chunk(x,y).takeChange() ) { // ### should at least make bands rgn |= QRegion( x*chunksize-area.x(), y*chunksize-area.y(), chunksize,chunksize ); // allvisible += *chunk(x,y).listPtr(); setNeedRedraw( chunk(x,y).listPtr() ); // chunk(x,y).listPtr()->first()->m_bNeedRedraw = true; } } else { // allvisible += *chunk(x,y).listPtr(); setNeedRedraw( chunk(x,y).listPtr() ); } } } // allvisible.sort(); #if 0 // 2018.03.11 - double buffer is always false if ( double_buffer ) { offscr = QPixmap(area.width(), area.height()); if (p) offscr.x11SetScreen(p->device()->x11Screen()); } if ( double_buffer && !offscr.isNull() ) { QPainter painter; const bool isSucces = painter.begin(&offscr); if (!isSucces) { qWarning() << Q_FUNC_INFO << " " << __LINE__ << " painter not active "; } painter.translate(-area.x(),-area.y()); painter.setBrushOrigin(-area.x(),-area.y()); if ( p ) { painter.setClipRect(QRect(0,0,area.width(),area.height())); } else { painter.setClipRegion(rgn); } if (!painter.isActive()) { qWarning() << Q_FUNC_INFO << " " << __LINE__ << " painter is not active"; } drawBackground(painter,area); // allvisible.drawUnique(painter); drawChangedItems( painter ); drawForeground(painter,area); painter.end(); if ( p ) { p->drawPixmap( area.x(), area.y(), offscr, 0, 0, area.width(), area.height() ); return; } } else #endif if ( p ) { drawBackground(*p,area); // allvisible.drawUnique(*p); drawChangedItems( *p ); drawForeground(*p,area); return; } QPoint trtr; // keeps track of total translation of rgn trtr -= area.topLeft(); for ( QList::iterator itView = m_viewList.begin(); itView != m_viewList.end(); ++itView) { KtlQCanvasView* view = *itView; if ( !view->worldMatrix().isIdentity() ) continue; // Cannot paint those here (see callers). // as of my testing, drawing below always fails, so just post for an update event to the widget view->viewport()->update(); #if 0 //view->viewport()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); // note: remove this when possible //QPainter painter(view->viewport()); QPainter painter; const bool isSuccess = painter.begin(view->viewport()); static int paintSuccessCount = 0; static int paintFailCount = 0; if (!isSuccess) { //qWarning() << Q_FUNC_INFO << " on view " << view << " viewport " << view->viewport(); qWarning() << Q_FUNC_INFO << " " << __LINE__ << " painter not active, applying workaround"; // TODO fix this workaround for repainting: the painter would try to draw to the widget outside of a paint event, // which is not expected to work. Thus this code just sends an update() to the widget, ensuring correct painting ++paintFailCount; qWarning() << Q_FUNC_INFO << " paint success: " << paintSuccessCount << ", fail: " << paintFailCount; view->viewport()->update(); continue; } else { ++paintSuccessCount; } QPoint tr = view->contentsToViewport(area.topLeft()); QPoint nrtr = view->contentsToViewport(QPoint(0,0)); // new translation QPoint rtr = nrtr - trtr; // extra translation of rgn trtr += rtr; // add to total if (double_buffer) { rgn.translate(rtr.x(),rtr.y()); painter.setClipRegion(rgn); painter.drawPixmap(tr,offscr, QRect(QPoint(0,0),area.size())); } else { painter.translate(nrtr.x(),nrtr.y()); rgn.translate(rtr.x(),rtr.y()); painter.setClipRegion(rgn); drawBackground(painter,area); // allvisible.drawUnique(painter); drawChangedItems( painter ); drawForeground(painter,area); painter.translate(-nrtr.x(),-nrtr.y()); } #endif } } void KtlQCanvas::setNeedRedraw( const KtlQCanvasItemList * list ) { KtlQCanvasItemList::const_iterator end = list->end(); for ( KtlQCanvasItemList::const_iterator it = list->begin(); it != end; ++it ) (*it)->setNeedRedraw( true ); } void KtlQCanvas::drawChangedItems( QPainter & painter ) { SortedCanvasItems::iterator end = m_canvasItems.end(); for ( SortedCanvasItems::iterator it = m_canvasItems.begin(); it != end; ++it ) { KtlQCanvasItem * i = it->second; if ( i->needRedraw() ) { i->draw( painter ); i->setNeedRedraw( false ); } } } /*! \internal This method to informs the KtlQCanvas that a given chunk is `dirty' and needs to be redrawn in the next Update. (\a x,\a y) is a chunk location. The sprite classes call this. Any new derived class of KtlQCanvasItem must do so too. SetChangedChunkContaining can be used instead. */ void KtlQCanvas::setChangedChunk(int x, int y) { if (validChunk(x,y)) { KtlQCanvasChunk& ch=chunk(x,y); ch.change(); } } /*! \internal This method to informs the KtlQCanvas that the chunk containing a given pixel is `dirty' and needs to be redrawn in the next Update. (\a x,\a y) is a pixel location. The item classes call this. Any new derived class of KtlQCanvasItem must do so too. SetChangedChunk can be used instead. */ void KtlQCanvas::setChangedChunkContaining(int x, int y) { if ( onCanvas(x, y) ) { KtlQCanvasChunk& chunk=chunkContaining(x,y); chunk.change(); } } /*! \internal This method adds the KtlQCanvasItem \a g to the list of those which need to be drawn if the given chunk at location ( \a x, \a y ) is redrawn. Like SetChangedChunk and SetChangedChunkContaining, this method marks the chunk as `dirty'. */ void KtlQCanvas::addItemToChunk(KtlQCanvasItem* g, int x, int y) { if (validChunk(x, y) ) { chunk(x,y).add(g); } } /*! \internal This method removes the KtlQCanvasItem \a g from the list of those which need to be drawn if the given chunk at location ( \a x, \a y ) is redrawn. Like SetChangedChunk and SetChangedChunkContaining, this method marks the chunk as `dirty'. */ void KtlQCanvas::removeItemFromChunk(KtlQCanvasItem* g, int x, int y) { if (validChunk(x,y)) { chunk(x,y).remove(g); } } /*! \internal This method adds the KtlQCanvasItem \a g to the list of those which need to be drawn if the chunk containing the given pixel ( \a x, \a y ) is redrawn. Like SetChangedChunk and SetChangedChunkContaining, this method marks the chunk as `dirty'. */ void KtlQCanvas::addItemToChunkContaining(KtlQCanvasItem* g, int x, int y) { if ( onCanvas( x, y ) ) { chunkContaining(x,y).add(g); } } /*! \internal This method removes the KtlQCanvasItem \a g from the list of those which need to be drawn if the chunk containing the given pixel ( \a x, \a y ) is redrawn. Like SetChangedChunk and SetChangedChunkContaining, this method marks the chunk as `dirty'. */ void KtlQCanvas::removeItemFromChunkContaining(KtlQCanvasItem* g, int x, int y) { if ( onCanvas( x, y ) ) { chunkContaining(x,y).remove(g); } } /*! Returns the color set by setBackgroundColor(). By default, this is white. This function is not a reimplementation of QWidget::backgroundColor() (KtlQCanvas is not a subclass of QWidget), but all QCanvasViews that are viewing the canvas will set their backgrounds to this color. \sa setBackgroundColor(), backgroundPixmap() */ QColor KtlQCanvas::backgroundColor() const { return bgcolor; } /*! Sets the solid background to be the color \a c. \sa backgroundColor(), setBackgroundPixmap(), setTiles() */ void KtlQCanvas::setBackgroundColor( const QColor& c ) { if ( bgcolor != c ) { bgcolor = c; for (QList::iterator itView = m_viewList.begin(); itView != m_viewList.end(); ++itView) { KtlQCanvasView* view = *itView; /* XXX this doesn't look right. Shouldn't this be more like setBackgroundPixmap? : Ian */ //view->viewport()->setEraseColor( bgcolor ); // 2018.11.21 QWidget *viewportWidg = view->viewport(); QPalette palette; palette.setColor(viewportWidg->backgroundRole(), bgcolor); viewportWidg->setPalette(palette); } setAllChanged(); } } /*! Returns the pixmap set by setBackgroundPixmap(). By default, this is a null pixmap. \sa setBackgroundPixmap(), backgroundColor() */ QPixmap KtlQCanvas::backgroundPixmap() const { return pm; } /*! Sets the solid background to be the pixmap \a p repeated as necessary to cover the entire canvas. \sa backgroundPixmap(), setBackgroundColor(), setTiles() */ void KtlQCanvas::setBackgroundPixmap( const QPixmap& p ) { setTiles(p, 1, 1, p.width(), p.height()); for (QList::iterator itView = m_viewList.begin(); itView != m_viewList.end(); ++itView) { (*itView)->updateContents(); } //KtlQCanvasView* view = m_viewList.first(); // 2018.08.14 - see above //while ( view != 0 ) { // view->updateContents(); // view = m_viewList.next(); //} } /*! This virtual function is called for all updates of the canvas. It renders any background graphics using the painter \a painter, in the area \a clip. If the canvas has a background pixmap or a tiled background, that graphic is used, otherwise the canvas is cleared using the background color. If the graphics for an area change, you must explicitly call setChanged(const QRect&) for the result to be visible when update() is next called. \sa setBackgroundColor(), setBackgroundPixmap(), setTiles() */ void KtlQCanvas::drawBackground(QPainter& painter, const QRect& clip) { painter.fillRect( clip, Qt::white ); if ( pm.isNull() ) painter.fillRect(clip,bgcolor); else if ( !grid ) { for (int x=clip.x()/pm.width(); x<(clip.x()+clip.width()+pm.width()-1)/pm.width(); x++) { for (int y=clip.y()/pm.height(); y<(clip.y()+clip.height()+pm.height()-1)/pm.height(); y++) { painter.drawPixmap(x*pm.width(), y*pm.height(),pm); } } } else { const int x1 = roundDown( clip.left(), tilew ); int x2 = roundDown( clip.right(), tilew ); const int y1 = roundDown( clip.top(), tileh ); int y2 = roundDown( clip.bottom(), tileh ); const int roww = pm.width()/tilew; for (int j=y1; j<=y2; j++) { int tv = tilesVertically(); int jj = ((j%tv)+tv)%tv; for (int i=x1; i<=x2; i++) { int th = tilesHorizontally(); int ii = ((i%th)+th)%th; int t = tile(ii,jj); int tx = t % roww; int ty = t / roww; painter.drawPixmap( i*tilew, j*tileh, pm, tx*tilew, ty*tileh, tilew, tileh ); } } } } void KtlQCanvas::drawForeground(QPainter& painter, const QRect& clip) { if ( debug_redraw_areas ) { painter.setPen( Qt::red ); painter.setBrush(Qt::NoBrush); painter.drawRect(clip); } } void KtlQCanvas::setTiles( QPixmap p, int h, int v, int tilewidth, int tileheight ) { if ( !p.isNull() && (!tilewidth || !tileheight || p.width() % tilewidth != 0 || p.height() % tileheight != 0 ) ) return; htiles = h; vtiles = v; delete[] grid; pm = p; if ( h && v && !p.isNull() ) { grid = new ushort[h*v]; memset( grid, 0, h*v*sizeof(ushort) ); tilew = tilewidth; tileh = tileheight; } else { grid = 0; } if ( h + v > 10 ) { int s = scm(tilewidth,tileheight); retune( s < 128 ? s : qMax(tilewidth,tileheight) ); } setAllChanged(); } void KtlQCanvas::setTile( int x, int y, int tilenum ) { ushort& t = grid[x+y*htiles]; if ( t != tilenum ) { t = tilenum; if ( tilew == tileh && tilew == chunksize ) setChangedChunk( x, y ); // common case else setChanged( QRect(x*tilew,y*tileh,tilew,tileh) ); } } KtlQCanvasItemList KtlQCanvas::collisions(const QPoint& p) /* const */ { return collisions(QRect(p,QSize(1,1))); } KtlQCanvasItemList KtlQCanvas::collisions(const QRect& r) /* const */ { KtlQCanvasRectangle *i = new KtlQCanvasRectangle(r, /*(KtlQCanvas*) */ this); // TODO verify here, why is crashing ?! i->setPen( QPen( Qt::NoPen) ); i->show(); // doesn't actually show, since we destroy it KtlQCanvasItemList l = i->collisions(true); delete i; l.sort(); return l; } KtlQCanvasItemList KtlQCanvas::collisions(const QPolygon& chunklist, const KtlQCanvasItem* item, bool exact) const { if (isCanvasDebugEnabled()) { qDebug() << Q_FUNC_INFO << " test item: " << item; for (SortedCanvasItems::const_iterator itIt = m_canvasItems.begin(); itIt != m_canvasItems.end(); ++itIt) { const KtlQCanvasItem *i = itIt->second; qDebug() << " in canvas item: " << i; } qDebug() << "end canvas item list"; } //Q3PtrDict seen; QHash seen; KtlQCanvasItemList result; for (int i=0; i<(int)chunklist.count(); i++) { int x = chunklist[i].x(); int y = chunklist[i].y(); if ( validChunk(x,y) ) { const KtlQCanvasItemList* l = chunk(x,y).listPtr(); for (KtlQCanvasItemList::ConstIterator it=l->begin(); it!=l->end(); ++it) { KtlQCanvasItem *g=*it; if ( g != item ) { //if ( !seen.find(g) ) { if ( seen.find(g) == seen.end() ) { //seen.replace(g,(void*)1); seen.take(g); seen.insert(g, true); //if ( !exact || item->collidesWith(g) ) // result.append(g); if (!exact) { result.append(g); } if (isCanvasDebugEnabled()) { qDebug() <<"test collides " << item << " with " << g; } if (item->collidesWith(g)) { result.append(g); } } } } } } return result; } KtlQCanvasView::KtlQCanvasView(QWidget* parent, const char* name, Qt::WFlags f) - : Q3ScrollView(parent,name,f|Qt::WResizeNoErase|Qt::WStaticContents) // TODO QT3 + : KtlQ3ScrollView(parent,name,f|Qt::WResizeNoErase|Qt::WStaticContents) // TODO QT3 { d = new KtlQCanvasViewData; viewing = 0; setCanvas(0); connect(this,SIGNAL(contentsMoving(int,int)),this,SLOT(cMoving(int,int))); } KtlQCanvasView::KtlQCanvasView(KtlQCanvas* canvas, QWidget* parent, const char* name, Qt::WFlags f) - : Q3ScrollView(parent,name,f|Qt::WResizeNoErase|Qt::WStaticContents) // TODO QT3 + : KtlQ3ScrollView(parent,name,f|Qt::WResizeNoErase|Qt::WStaticContents) // TODO QT3 { d = new KtlQCanvasViewData; viewing = 0; setCanvas(canvas); connect(this,SIGNAL(contentsMoving(int,int)),this,SLOT(cMoving(int,int))); } KtlQCanvasView::~KtlQCanvasView() { delete d; d = NULL; setCanvas(0); } void KtlQCanvasView::setCanvas(KtlQCanvas* canvas) { if (viewing) { disconnect(viewing); viewing->removeView(this); } viewing=canvas; if (viewing) { connect(viewing,SIGNAL(resized()), this, SLOT(updateContentsSize())); viewing->addView(this); } if ( d ) // called by d'tor updateContentsSize(); } const QMatrix &KtlQCanvasView::worldMatrix() const { return d->xform; } const QMatrix &KtlQCanvasView::inverseWorldMatrix() const { return d->ixform; } bool KtlQCanvasView::setWorldMatrix( const QMatrix & wm ) { bool ok = wm.isInvertible(); if ( ok ) { d->xform = wm; d->ixform = wm.inverted(); updateContentsSize(); viewport()->update(); } return ok; } void KtlQCanvasView::updateContentsSize() { if ( viewing ) { QRect br; // br = d->xform.map(QRect(0,0,viewing->width(),viewing->height())); br = d->xform.mapRect(viewing->rect()); if ( br.width() < contentsWidth() ) { QRect r(contentsToViewport(QPoint(br.width(),0)), QSize(contentsWidth()-br.width(),contentsHeight())); //viewport()->erase(r); // 2015.11.25 - not recommended to directly repaint viewport()->update(r); } if ( br.height() < contentsHeight() ) { QRect r(contentsToViewport(QPoint(0,br.height())), QSize(contentsWidth(),contentsHeight()-br.height())); //viewport()->erase(r); // 2015.11.25 - not recommended to directly repaint viewport()->update(r); } resizeContents(br.width(),br.height()); } else { //viewport()->erase(); // 2015.11.25 - not recommended to directly repaint viewport()->update(); resizeContents(1,1); } } void KtlQCanvasView::cMoving(int x, int y) { // A little kludge to smooth up repaints when scrolling int dx = x - contentsX(); int dy = y - contentsY(); d->repaint_from_moving = abs(dx) < width() / 8 && abs(dy) < height() / 8; } /*! Repaints part of the KtlQCanvas that the canvas view is showing starting at \a cx by \a cy, with a width of \a cw and a height of \a ch using the painter \a p. \warning When double buffering is enabled, drawContents() will not respect the current settings of the painter when setting up the painter for the double buffer (e.g., viewport() and window()). Also, be aware that KtlQCanvas::update() bypasses drawContents(), which means any reimplementation of drawContents() is not called. \sa setDoubleBuffering() */ void KtlQCanvasView::drawContents(QPainter *p, int cx, int cy, int cw, int ch) { QRect r(cx,cy,cw,ch); r = r.normalized(); if (viewing) { //viewing->drawViewArea(this,p,r,true); viewing->drawViewArea(this,p,r, /*!d->repaint_from_moving*/ false); /* 2018.03.11 - fix build for osx */ d->repaint_from_moving = false; } else { p->eraseRect(r); } } /*! \reimp \internal (Implemented to get rid of a compiler warning.) */ void KtlQCanvasView::drawContents( QPainter *p ) { qDebug() << Q_FUNC_INFO << " called, altough not expected"; drawContents(p, 0, 0, width(), height()); } /*! Suggests a size sufficient to view the entire canvas. */ QSize KtlQCanvasView::sizeHint() const { if ( !canvas() ) - return Q3ScrollView::sizeHint(); // TODO QT3 + return KtlQ3ScrollView::sizeHint(); // TODO QT3 // should maybe take transformations into account return ( canvas()->size() + 2 * QSize(frameWidth(), frameWidth()) ) .boundedTo( 3 * QApplication::desktop()->size() / 4 ); } #include "canvas.moc" diff --git a/src/canvas.h b/src/canvas.h index 7b18fa15..3c865f94 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -1,192 +1,192 @@ /*************************************************************************** * Copyright (C) 1999-2005 Trolltech AS * * Copyright (C) 2006 David Saxton * * * * This file may be distributed and/or modified under the terms of the * * GNU General Public License version 2 as published by the Free * * Software Foundation * ***************************************************************************/ #ifndef QCANVAS_H #define QCANVAS_H #include -#include "ktlqt3support/q3scrollview.h" +#include "ktlqt3support/ktlq3scrollview.h" #include "qpixmap.h" // #include "q3ptrlist.h" #include "qbrush.h" #include "qpen.h" #include "qlist.h" // #include "q3pointarray.h" // 2018.08.14 #include "canvasitemlist.h" class KtlQCanvasView; class KtlQCanvasChunk; class KtlQCanvas : public QObject { Q_OBJECT public: KtlQCanvas( QObject* parent = 0, const char* name = 0 ); KtlQCanvas( const int w, const int h); KtlQCanvas( QPixmap p, int h, int v, int tilewidth, int tileheight ); virtual ~KtlQCanvas(); virtual void setTiles( QPixmap tiles, int h, int v, int tilewidth, int tileheight ); virtual void setBackgroundPixmap( const QPixmap& p ); QPixmap backgroundPixmap() const; virtual void setBackgroundColor( const QColor& c ); QColor backgroundColor() const; virtual void setTile( int x, int y, int tilenum ); int tile( int x, int y ) const { return grid[x+y*htiles]; } int tilesHorizontally() const { return htiles; } int tilesVertically() const { return vtiles; } int tileWidth() const { return tilew; } int tileHeight() const { return tileh; } virtual void resize( const QRect & newSize ); int width() const { return size().width(); } int height() const { return size().height(); } QSize size() const { return m_size.size(); } QRect rect() const { return m_size; } bool onCanvas( const int x, const int y ) const { return onCanvas( QPoint( x, y ) ); } bool onCanvas( const QPoint& p ) const { return m_size.contains( p ); } bool validChunk( const int x, const int y ) const { return validChunk( QPoint( x, y ) ); } bool validChunk( const QPoint& p ) const { return m_chunkSize.contains( p ); } int chunkSize() const { return chunksize; } virtual void retune(int chunksize, int maxclusters=100); virtual void setChangedChunk(int i, int j); virtual void setChangedChunkContaining(int x, int y); virtual void setAllChanged(); virtual void setChanged(const QRect& area); virtual void setUnchanged(const QRect& area); // These call setChangedChunk. void addItemToChunk(KtlQCanvasItem*, int i, int j); void removeItemFromChunk(KtlQCanvasItem*, int i, int j); void addItemToChunkContaining(KtlQCanvasItem*, int x, int y); void removeItemFromChunkContaining(KtlQCanvasItem*, int x, int y); KtlQCanvasItemList allItems(); KtlQCanvasItemList collisions( const QPoint&) /* const */ ; KtlQCanvasItemList collisions( const QRect&) /* const */; KtlQCanvasItemList collisions( const QPolygon& pa, const KtlQCanvasItem* item, bool exact) const; void drawArea(const QRect&, QPainter* p); // These are for KtlQCanvasView to call virtual void addView(KtlQCanvasView*); virtual void removeView(KtlQCanvasView*); void drawCanvasArea(const QRect&, QPainter* p, bool double_buffer); void drawViewArea( KtlQCanvasView* view, QPainter* p, const QRect& r, bool dbuf ); // These are for KtlQCanvasItem to call virtual void addItem(KtlQCanvasItem*); virtual void removeItem(const KtlQCanvasItem*); virtual void setUpdatePeriod(int ms); int toChunkScaling( int x ) const; signals: void resized(); public slots: virtual void advance(); virtual void update(); protected: virtual void drawBackground(QPainter&, const QRect& area); virtual void drawForeground(QPainter&, const QRect& area); private: void init(int w, int h, int chunksze=16, int maxclust=100); void init(const QRect & r, int chunksze=16, int maxclust=100); void initChunkSize( const QRect & s ); KtlQCanvasChunk& chunk(int i, int j) const; KtlQCanvasChunk& chunkContaining(int x, int y) const; QRect changeBounds(const QRect& inarea); void drawChanges(const QRect& inarea); void drawChangedItems( QPainter & painter ); void setNeedRedraw( const KtlQCanvasItemList * list ); QPixmap offscr; int chunksize; int maxclusters; QRect m_size; QRect m_chunkSize; KtlQCanvasChunk* chunks; SortedCanvasItems m_canvasItems; QList m_viewList; void initTiles(QPixmap p, int h, int v, int tilewidth, int tileheight); ushort *grid; ushort htiles; ushort vtiles; ushort tilew; ushort tileh; bool oneone; QPixmap pm; QTimer* update_timer; QColor bgcolor; bool debug_redraw_areas; friend void qt_unview(KtlQCanvas* c); KtlQCanvas( const KtlQCanvas & ); KtlQCanvas &operator=( const KtlQCanvas & ); }; class KtlQCanvasViewData; -class KtlQCanvasView : public Q3ScrollView // TODO QT3 QScrollArea +class KtlQCanvasView : public KtlQ3ScrollView // TODO QT3 QScrollArea { Q_OBJECT public: KtlQCanvasView(QWidget* parent=0, const char* name=0, Qt::WFlags f=0); // 2018.08.15 - unused? KtlQCanvasView(KtlQCanvas* viewing, QWidget* parent=0, const char* name=0, Qt::WFlags f=0); ~KtlQCanvasView(); KtlQCanvas* canvas() const { return viewing; } void setCanvas(KtlQCanvas* v); const QMatrix &worldMatrix() const; const QMatrix &inverseWorldMatrix() const; bool setWorldMatrix( const QMatrix & ); protected: - /** overrides Q3ScrollView::drawContents() */ // override paintEvent? + /** overrides KtlQ3ScrollView::drawContents() */ // override paintEvent? virtual void drawContents( QPainter*, int cx, int cy, int cw, int ch ); QSize sizeHint() const; private: void drawContents( QPainter* ); KtlQCanvas* viewing; KtlQCanvasViewData* d; friend void qt_unview(KtlQCanvas* c); KtlQCanvasView( const KtlQCanvasView & ); KtlQCanvasView &operator=( const KtlQCanvasView & ); private slots: void cMoving(int,int); void updateContentsSize(); }; #endif // QCANVAS_H diff --git a/src/itemdocument.cpp b/src/itemdocument.cpp index e16825a8..03e03e03 100644 --- a/src/itemdocument.cpp +++ b/src/itemdocument.cpp @@ -1,1432 +1,1432 @@ /*************************************************************************** * Copyright (C) 2005 by David Saxton * * david@bluehaze.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. * ***************************************************************************/ #include "canvasitemparts.h" #include "canvasmanipulator.h" #include "cells.h" #include "circuitdocument.h" #include "connector.h" #include "cnitem.h" #include "drawpart.h" #include "ecnode.h" #include "flowcodedocument.h" #include "icnview.h" #include "itemdocumentdata.h" #include "itemgroup.h" #include "itemselector.h" #include "ktechlab.h" #include "pin.h" #include "resizeoverlay.h" #include "simulator.h" #include #include #include #include #include // #include //#include #include #include #include #include #include #include #include #include // #include #include #include #include // #include // 2018.08.13 - not needed #include #include #include #include #include #include #include //BEGIN class ItemDocument int ItemDocument::m_nextActionTicket = 0; ItemDocument::ItemDocument( const QString &caption, const char *name) : Document( caption, name ) { m_queuedEvents = 0; m_nextIdNum = 1; m_savedState = 0; m_currentState = 0; m_bIsLoading = false; m_canvas = new Canvas( this, "canvas" ); m_canvasTip = new CanvasTip(this,m_canvas); m_cmManager = new CMManager(this); updateBackground(); m_pUpdateItemViewScrollbarsTimer = new QTimer(this); connect( m_pUpdateItemViewScrollbarsTimer, SIGNAL(timeout()), this, SLOT(updateItemViewScrollbars()) ); m_pEventTimer = new QTimer(this); connect( m_pEventTimer, SIGNAL(timeout()), this, SLOT(processItemDocumentEvents()) ); connect( this, SIGNAL(selectionChanged()), this, SLOT(slotInitItemActions()) ); connect( ComponentSelector::self(), SIGNAL(itemClicked(const QString& )), this, SLOT(slotUnsetRepeatedItemId()) ); connect( FlowPartSelector::self(), SIGNAL(itemClicked(const QString& )), this, SLOT(slotUnsetRepeatedItemId()) ); #ifdef MECHANICS connect( MechanicsSelector::self(), SIGNAL(itemClicked(const QString& )), this, SLOT(slotUnsetRepeatedItemId()) ); #endif m_pAlignmentAction = new KActionMenu( i18n("Alignment") /*, "format-justify-right" */ , this ); m_pAlignmentAction->setObjectName("rightjust"); m_pAlignmentAction->setIcon( KIcon("format-justify-right") ); slotUpdateConfiguration(); } ItemDocument::~ItemDocument() { m_bDeleted = true; // ItemMap toDelete = m_itemList; const ItemMap::iterator end = m_itemList.end(); for ( ItemMap::iterator it = m_itemList.begin(); it != end; ++it ) { qDebug() << "ItemDocument::~ItemDocument: deleting [" << it.key() << "] " << it.value(); //delete *it; // 2015.07.31 - this will crash it.value()->deleteLater(); } m_itemList.clear(); cleanClearStack( m_undoStack ); cleanClearStack( m_redoStack ); delete m_cmManager; delete m_currentState; delete m_canvasTip; } void ItemDocument::handleNewView( View * view ) { Document::handleNewView(view); requestEvent( ItemDocument::ItemDocumentEvent::ResizeCanvasToItems ); } bool ItemDocument::registerItem(KtlQCanvasItem *qcanvasItem) { if (!qcanvasItem) return false; requestEvent( ItemDocument::ItemDocumentEvent::ResizeCanvasToItems ); if(Item *item = dynamic_cast(qcanvasItem) ) { m_itemList[ item->id() ] = item; connect( item, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()) ); itemAdded(item); return true; } return false; } void ItemDocument::slotSetDrawAction(QAction *selected) { int drawAction = selected->data().toInt(); m_cmManager->setDrawAction(drawAction); } void ItemDocument::cancelCurrentOperation() { m_cmManager->cancelCurrentManipulation(); } void ItemDocument::slotSetRepeatedItemId( const QString &id ) { m_cmManager->setCMState( CMManager::cms_repeated_add, true ); m_cmManager->setRepeatedAddId(id); } void ItemDocument::slotUnsetRepeatedItemId() { m_cmManager->setCMState( CMManager::cms_repeated_add, false ); } void ItemDocument::fileSave() { if ( url().isEmpty() && !getURL(m_fileExtensionInfo) ) return; writeFile(); } void ItemDocument::fileSaveAs() { if ( !getURL(m_fileExtensionInfo) ) return; writeFile(); // Our modified state may not have changed, but we emit this to force the // main window to update our caption. emit modifiedStateChanged(); } void ItemDocument::writeFile() { ItemDocumentData data( type() ); data.saveDocumentState(this); if ( data.saveData(url()) ) { m_savedState = m_currentState; setModified(false); } } bool ItemDocument::openURL( const KUrl &url ) { ItemDocumentData data( type() ); if ( !data.loadData(url) ) return false; // Why do we stop simulating while loading a document? // Crash possible when loading a circuit document, and the Qt event loop is // reentered (such as when a PIC component pops-up a message box), which // will then call the Simulator::step function, which might use components // that have not fully initialized themselves. m_bIsLoading = true; bool wasSimulating = Simulator::self()->isSimulating(); Simulator::self()->slotSetSimulating( false ); data.restoreDocument(this); Simulator::self()->slotSetSimulating( wasSimulating ); m_bIsLoading = false; setURL(url); clearHistory(); m_savedState = m_currentState; setModified(false); if ( FlowCodeDocument *fcd = dynamic_cast(this) ) { // We need to tell all pic-depedent components about what pic type is in use emit fcd->picTypeChanged(); } requestEvent( ItemDocument::ItemDocumentEvent::ResizeCanvasToItems ); // Load Z-position info m_zOrder.clear(); ItemMap::iterator end = m_itemList.end(); for ( ItemMap::iterator it = m_itemList.begin(); it != end; ++it ) { if ( !*it || (*it)->parentItem() ) continue; m_zOrder[(*it)->baseZ()] = *it; } slotUpdateZOrdering(); return true; } void ItemDocument::print() { static QPrinter * printer = new QPrinter; //if ( ! printer->setup( KTechlab::self() ) ) // return; QPrintDialog printDialog(printer, KTechlab::self()); if ( ! printDialog.exec() ) { return; } // setup the printer. with Qt, you always "print" to a // QPainter.. whether the output medium is a pixmap, a screen, // or paper QPainter p; p.begin( printer ); // we let our view do the actual printing //Q3PaintDeviceMetrics metrics( printer ); // 2018.08.13 - replaced with method call QRect pageRect = printer->pageRect(); // Round to 16 so that we cut in the middle of squares int w = pageRect.width(); w = (w & 0xFFFFFFF0) + ((w << 1) & 0x10); int h = pageRect.height(); h = (h & 0xFFFFFFF0) + ((h << 1) & 0x10); p.setClipping( true ); p.setClipRect( 0, 0, w, h, /* QPainter::CoordPainter */ Qt::ReplaceClip ); // TODO is this correct? // Send off the painter for drawing m_canvas->setBackgroundPixmap( 0 ); QRect bounding = canvasBoundingRect(); unsigned int rows = (unsigned) std::ceil( double( bounding.height() ) / double( h ) ); unsigned int cols = (unsigned) std::ceil( double( bounding.width() ) / double( w ) ); int offset_x = bounding.x(); int offset_y = bounding.y(); for ( unsigned row = 0; row < rows; ++row ) { for ( unsigned col = 0; col < cols; ++col ) { if ( row != 0 || col != 0 ) printer->newPage(); QRect drawArea( offset_x + (col * w), offset_y + (row * h), w, h ); m_canvas->drawArea( drawArea, & p ); p.translate( -w, 0 ); } p.translate( w * cols, -h ); } updateBackground(); // and send the result to the printer p.end(); } void ItemDocument::requestStateSave( int actionTicket ) { if ( m_bIsLoading ) return; cleanClearStack( m_redoStack ); if ( (actionTicket >= 0) && (actionTicket == m_currentActionTicket) ) { delete m_currentState; m_currentState = 0; } m_currentActionTicket = actionTicket; //FIXME: it is possible, that we push something here, also nothing has changed, yet. // to reproduce do: // 1. select an item -> something is pushed onto undoStack, but nothing changed // 2. select Undo -> pushed on redoStack, pop from undoStack // 3. deselect item -> there is still something on the redoStack // // this way you can fill up the redoStack, as you like :-/ if (m_currentState) m_undoStack.push(m_currentState); m_currentState = new ItemDocumentData( type() ); m_currentState->saveDocumentState(this); if (!m_savedState) m_savedState = m_currentState; setModified( m_savedState != m_currentState ); emit undoRedoStateChanged(); //FIXME To resize undo queue, have to pop and push everything // In Qt4 QStack is used and QStack inherits QVector, that should // make it a bit more easy int maxUndo = KTLConfig::maxUndo(); if ( maxUndo <= 0 || m_undoStack.count() < (unsigned)maxUndo ) return; IDDStack tempStack; int pushed = 0; while ( !m_undoStack.isEmpty() && pushed < maxUndo ) { tempStack.push( m_undoStack.pop() ); pushed++; } cleanClearStack( m_undoStack ); while ( !tempStack.isEmpty() ) m_undoStack.push( tempStack.pop() ); } void ItemDocument::cleanClearStack( IDDStack &stack ) { while ( !stack.isEmpty() ) { ItemDocumentData * idd = stack.pop(); if ( m_currentState != idd ) delete idd; } } void ItemDocument::clearHistory() { cleanClearStack( m_undoStack ); cleanClearStack( m_redoStack ); delete m_currentState; m_currentState = 0; requestStateSave(); } bool ItemDocument::isUndoAvailable() const { return !m_undoStack.isEmpty(); } bool ItemDocument::isRedoAvailable() const { return !m_redoStack.isEmpty(); } void ItemDocument::undo() { if (m_undoStack.empty()) { return; } ItemDocumentData *idd = m_undoStack.pop(); if (!idd) return; if (m_currentState) m_redoStack.push(m_currentState); idd->restoreDocument(this); m_currentState = idd; setModified( m_savedState != m_currentState ); emit undoRedoStateChanged(); } void ItemDocument::redo() { if (m_redoStack.empty()) { return; } ItemDocumentData *idd = m_redoStack.pop(); if (!idd) return; if (m_currentState) m_undoStack.push(m_currentState); idd->restoreDocument(this); m_currentState = idd; setModified( m_savedState != m_currentState ); emit undoRedoStateChanged(); } void ItemDocument::cut() { copy(); deleteSelection(); } void ItemDocument::paste() { QString xml = QApplication::clipboard()->text( QClipboard::Clipboard ); if ( xml.isEmpty() ) return; unselectAll(); ItemDocumentData data( type() ); if ( !data.fromXML(xml) ) return; data.generateUniqueIDs(this); // data.translateContents( 64, 64 ); data.mergeWithDocument( this, true ); // Get rid of any garbage that shouldn't be around / merge connectors / etc flushDeleteList(); requestStateSave(); } Item *ItemDocument::itemWithID( const QString &id ) { if ( m_itemList.contains( id ) ) return m_itemList[id]; else return 0; } void ItemDocument::unselectAll() { selectList()->removeAllItems(); } void ItemDocument::select( KtlQCanvasItem * item ) { if (!item) return; item->setSelected( selectList()->contains( item ) || selectList()->addQCanvasItem( item ) ); } void ItemDocument::select( const KtlQCanvasItemList & list ) { const KtlQCanvasItemList::const_iterator end = list.end(); for ( KtlQCanvasItemList::const_iterator it = list.begin(); it != end; ++it ) selectList()->addQCanvasItem(*it); selectList()->setSelected(true); } void ItemDocument::unselect( KtlQCanvasItem *qcanvasItem ) { selectList()->removeQCanvasItem(qcanvasItem); qcanvasItem->setSelected(false); } void ItemDocument::slotUpdateConfiguration() { updateBackground(); m_canvas->setUpdatePeriod( int(1000./KTLConfig::refreshRate()) ); } KtlQCanvasItem* ItemDocument::itemAtTop( const QPoint &pos ) const { KtlQCanvasItemList list = m_canvas->collisions( QRect( pos.x()-1, pos.y()-1, 3, 3 ) ); // note: m_canvas is actually modified here KtlQCanvasItemList::const_iterator it = list.begin(); const KtlQCanvasItemList::const_iterator end = list.end(); while ( it != end ) { KtlQCanvasItem *item = *it; if( !dynamic_cast(item) && !dynamic_cast(item) && !dynamic_cast(item) && !dynamic_cast(item) && !dynamic_cast(item) ) { ++it; } else { if ( ConnectorLine * l = dynamic_cast(item) ) return l->parent(); return item; } } return 0; } // these look dangerous., see todo in header file. void ItemDocument::alignHorizontally( ) { selectList()->slotAlignHorizontally(); if ( ICNDocument *icnd = dynamic_cast(this) ) icnd->requestRerouteInvalidatedConnectors(); } void ItemDocument::alignVertically( ) { selectList()->slotAlignVertically(); if ( ICNDocument *icnd = dynamic_cast(this) ) icnd->requestRerouteInvalidatedConnectors(); } void ItemDocument::distributeHorizontally( ) { selectList()->slotDistributeHorizontally(); if ( ICNDocument *icnd = dynamic_cast(this) ) icnd->requestRerouteInvalidatedConnectors(); } void ItemDocument::distributeVertically( ) { selectList()->slotDistributeVertically(); if ( ICNDocument *icnd = dynamic_cast(this) ) icnd->requestRerouteInvalidatedConnectors(); } // ########################### bool ItemDocument::registerUID( const QString &UID ) { return m_idList.insert(UID).second; } void ItemDocument::unregisterUID( const QString & uid ) { m_idList.erase(uid); m_itemList.remove(uid); } QString ItemDocument::generateUID( QString name ) { name.remove( QRegExp("__.*") ); // Change 'node__13' to 'node', for example QString idAttempt = name; while ( !registerUID(idAttempt) ) idAttempt = name + "__" + QString::number(m_nextIdNum++); return idAttempt; } // FIXME: popup menu doesn't seem to work these days. =( void ItemDocument::canvasRightClick( const QPoint &pos, KtlQCanvasItem* item ) { if (item) { if ( dynamic_cast(item) && !item->isSelected() ) { unselectAll(); select(item); } } KTechlab::self()->unplugActionList("alignment_actionlist"); KTechlab::self()->unplugActionList("orientation_actionlist"); fillContextMenu(pos); QMenu *pop = static_cast(KTechlab::self()->factory()->container("item_popup", KTechlab::self() )); if (!pop) return; pop->popup(pos); } void ItemDocument::fillContextMenu( const QPoint & pos ) { Q_UNUSED(pos); ItemView * activeItemView = dynamic_cast(activeView()); if ( !KTechlab::self() || !activeItemView ) return; QAction * align_actions[] = { activeItemView->actionByName("align_horizontally"), activeItemView->actionByName("align_vertically"), activeItemView->actionByName("distribute_horizontally"), activeItemView->actionByName("distribute_vertically") }; bool enableAlignment = selectList()->itemCount() > 1; if ( !enableAlignment ) return; for ( unsigned i = 0; i < 4; ++i ) { align_actions[i]->setEnabled(true); m_pAlignmentAction->removeAction( align_actions[i] ); //m_pAlignmentAction->insert( align_actions[i] ); m_pAlignmentAction->addAction( align_actions[i] ); } //Q3PtrList alignment_actions; QList alignment_actions; alignment_actions.append( m_pAlignmentAction ); KTechlab::self()->plugActionList( "alignment_actionlist", alignment_actions ); } void ItemDocument::slotInitItemActions() { ItemView * activeItemView = dynamic_cast(activeView()); if ( !KTechlab::self() || !activeItemView ) return; QAction * align_actions[] = { activeItemView->actionByName("align_horizontally"), activeItemView->actionByName("align_vertically"), activeItemView->actionByName("distribute_horizontally"), activeItemView->actionByName("distribute_vertically") }; bool enableAlignment = selectList()->itemCount() > 1; for ( unsigned i = 0; i < 4; ++i ) align_actions[i]->setEnabled(enableAlignment); } void ItemDocument::updateBackground() { // Also used in the constructor to make the background initially. // Thoughts. // ~The pixmap could be done somehow with 1bpp. It might save some waste // I expect it won't hurt for now. // ~This is all rather static, only works with square etc... should be no prob. for most uses. IMO. // ~If you want, decide what maximum and minimum spacing should be, then enforce them // in the Config (I suppose you can use tags?) // ~Defaults based on the existing grid background png. It should produce identical results, to your // original png. // **** Below where it says "interval * 10", that decides how big the pixmap will be (always square) // Originally I set this to 32, which give 256x256 with 8 spacing, as that was the size of your pixmap // Are there any good reasons to make the a certain size? (i.e. big or small ?). int interval = 8; int bigness = interval * 10; QPixmap pm( bigness, bigness ); // pm.fill( KTLConfig::bgColor() ); // first fill the background colour in pm.fill( Qt::white ); if( KTLConfig::showGrid() ){ //QPainter p(&pm); // setup painter to draw on pixmap QPainter p; const bool isSuccess = p.begin(&pm); if (!isSuccess) { qWarning() << Q_FUNC_INFO << " painter is not active"; } p.setPen( KTLConfig::gridColor() ); // set forecolour // note: anything other than 8 borks this for( int i = (interval / 2); i < bigness; i+=interval ){ p.drawLine( 0, i, bigness, i ); // horizontal p.drawLine( i, 0, i, bigness ); // vertical } p.end(); // all done } //pm.setDefaultOptimization( QPixmap::BestOptim ); // TODO no longer available? m_canvas->setBackgroundPixmap(pm); // and the finale. } void ItemDocument::requestCanvasResize() { requestEvent( ItemDocumentEvent::ResizeCanvasToItems ); } void ItemDocument::requestEvent( ItemDocumentEvent::type type ) { m_queuedEvents |= type; m_pEventTimer->stop(); m_pEventTimer->setSingleShot(true); m_pEventTimer->start( 0 /*, true */ ); } void ItemDocument::processItemDocumentEvents() { // Copy it incase we have new events requested while doing this... unsigned queuedEvents = m_queuedEvents; m_queuedEvents = 0; if ( queuedEvents & ItemDocumentEvent::ResizeCanvasToItems ) resizeCanvasToItems(); if ( queuedEvents & ItemDocumentEvent::UpdateZOrdering ) slotUpdateZOrdering(); ICNDocument * icnd = dynamic_cast(this); if ( icnd && (queuedEvents & ItemDocumentEvent::UpdateNodeGroups) ) icnd->slotAssignNodeGroups(); if ( icnd && (queuedEvents & ItemDocumentEvent::RerouteInvalidatedConnectors) ) icnd->rerouteInvalidatedConnectors(); } void ItemDocument::resizeCanvasToItems() { QRect bound = canvasBoundingRect(); m_viewList.removeAll((View*)0); const ViewList::iterator end = m_viewList.end(); for ( ViewList::iterator it = m_viewList.begin(); it != end; ++it ) { ItemView * iv = static_cast((View*)*it); CVBEditor * cvbEditor = iv->cvbEditor(); QPoint topLeft = iv->mousePosToCanvasPos( QPoint( 0, 0 ) ); int width = int( cvbEditor->visibleWidth() / iv->zoomLevel() ); int height = int( cvbEditor->visibleHeight() / iv->zoomLevel() ); QRect r( topLeft, QSize( width, height ) ); bound |= r; // kDebug() << "r="<setObjectName( "cropCheck" ); cropCheck->setChecked(true); // yes by default? // we need an object so we can retrieve which image type was selected by the user // so setup the filedialog. QString f; f = QString("*.png|%1\n*.bmp|%2\n*.svg|%3").arg( i18n("PNG Image") ).arg( i18n("BMP Image") ).arg( i18n("SVG Image") ); //KFileDialog exportDialog( KUrl() /*QString::null */, f, KTechlab::self(), i18n("Export As Image"), true, cropCheck); KFileDialog exportDialog( KUrl(), f, KTechlab::self(), /*i18n("Export As Image"),*/ /* true, */ cropCheck); exportDialog.setModal(true); exportDialog.setCaption(i18n("Export As Image")); exportDialog.setOperationMode( KFileDialog::Saving ); // now actually show it if ( exportDialog.exec() == QDialog::Rejected ) return; KUrl url = exportDialog.selectedUrl(); if ( url.isEmpty() ) return; if ( QFile::exists( url.path() ) ) { int query = KMessageBox::warningYesNo( KTechlab::self(), i18n( "A file named \"%1\" already exists. " "Are you sure you want to overwrite it?", url.fileName() ), i18n( "Overwrite File?" )); if ( query == KMessageBox::No ) return; } // with Qt, you always "print" to a // QPainter.. whether the output medium is a pixmap, a screen, // or paper // needs to be something like QPicture to do SVG etc... QRect saveArea; QString type; QRect cropArea; QPaintDevice *outputImage; QString filter = exportDialog.currentFilter(); filter = filter.toLower(); // gently soften the appearance of the letters. // did have a switch here but seems you can't use that on strings if ( filter == "*.png") type = "PNG"; else if ( filter == "*.bmp") type = "BMP"; else if ( filter == "*.svg" ) { KMessageBox::information( NULL, i18n("SVG export is sub-functional"), i18n("Export As Image") ); type = "SVG"; } // I don't like forcing people to use the right extension (personally) // but it is the easiest way to decide image type. else { KMessageBox::sorry( NULL, i18n("Unknown extension, please select one from the filter list."), i18n("Export As Image") ); return; } if ( cropCheck->isChecked() ) { cropArea = canvasBoundingRect(); if ( cropArea.isNull() ) { KMessageBox::sorry( 0l, i18n("There is nothing to crop"), i18n("Export As Image") ); return; } else { cropArea &= canvas()->rect(); } } saveArea = m_canvas->rect(); if ( type == "PNG" || type == "BMP" ) outputImage = new QPixmap( saveArea.size() ); else if ( type == "SVG" ) { setSVGExport(true); outputImage = new QPicture(); // svg can't be cropped using the qimage method. saveArea = cropArea; } else { kWarning() << "Unknown type!" << endl; return; } //2018.05.05 - extract to a method // //QPainter p(outputImage); // 2016.05.03 - explicitly initialize painter // QPainter p; // const bool isBeginSuccess = p.begin(outputImage); // if (!isBeginSuccess) { // qWarning() << Q_FUNC_INFO << " painter not active"; // } // // m_canvas->setBackgroundPixmap(QPixmap()); // m_canvas->drawArea( saveArea, &p ); // updateBackground(); // // p.end(); exportToImageDraw(saveArea, *outputImage); bool saveResult; // if cropping we need to convert to an image, // crop, then save. if ( cropCheck->isChecked() ) { if( type == "SVG" ) saveResult = dynamic_cast(outputImage)->save( url.path(), type.toLatin1().data()); else { QImage img = dynamic_cast(outputImage)->toImage(); if ( saveArea.x() < 0 ) { cropArea.translate( - saveArea.x(), 0 ); } if ( saveArea.y() < 0 ) { cropArea.translate( 0, - saveArea.y() ); } qDebug() << Q_FUNC_INFO << " cropArea " << cropArea; QImage imgCropped = img.copy(cropArea); saveResult = imgCropped.save(url.path(),type.toLatin1().data()); } } else { if ( type=="SVG" ) saveResult = dynamic_cast(outputImage)->save( url.path(), type.toLatin1().data() ); else saveResult = dynamic_cast(outputImage)->save( url.path(), type.toLatin1().data() ); } //if(saveResult == true) KMessageBox::information( this, i18n("Sucessfully exported to \"%1\"", url.filename() ), i18n("Image Export") ); //else KMessageBox::information( this, i18n("Export failed"), i18n("Image Export") ); if ( type == "SVG" ) setSVGExport(false); if (saveResult == false) KMessageBox::information( KTechlab::self(), i18n("Export failed"), i18n("Image Export") ); delete outputImage; } void ItemDocument::exportToImageDraw( const QRect &saveArea, QPaintDevice &pDev) { qDebug() << Q_FUNC_INFO << " saveArea " << saveArea; //QPainter p(outputImage); // 2016.05.03 - explicitly initialize painter QPainter p; const bool isBeginSuccess = p.begin(&pDev); if (!isBeginSuccess) { qWarning() << Q_FUNC_INFO << " painter not active"; } QTransform transf; transf.translate( -saveArea.x(), -saveArea.y()); p.setTransform(transf); m_canvas->setBackgroundPixmap(QPixmap()); m_canvas->drawArea( saveArea, &p ); updateBackground(); p.end(); } void ItemDocument::setSVGExport( bool svgExport ) { // Find any items and tell them not to draw buttons or sliders KtlQCanvasItemList items = m_canvas->allItems(); const KtlQCanvasItemList::iterator end = items.end(); for ( KtlQCanvasItemList::Iterator it = items.begin(); it != end; ++it ) { if ( CNItem * cnItem = dynamic_cast(*it) ) cnItem->setDrawWidgets(!svgExport); } } void ItemDocument::raiseZ() { raiseZ( selectList()->items(true) ); } void ItemDocument::raiseZ( const ItemList & itemList ) { if ( m_zOrder.isEmpty() ) slotUpdateZOrdering(); if ( m_zOrder.isEmpty() ) return; IntItemMap::iterator begin = m_zOrder.begin(); IntItemMap::iterator previous = m_zOrder.end(); IntItemMap::iterator it = --m_zOrder.end(); do { Item * previousData = (previous == m_zOrder.end()) ? 0l : previous.value(); Item * currentData = it.value(); if ( currentData && previousData && itemList.contains(currentData) && !itemList.contains(previousData) ) { previous.value() = currentData; it.value() = previousData; } previous = it; --it; } while ( previous != begin ); slotUpdateZOrdering(); } void ItemDocument::lowerZ() { lowerZ( selectList()->items(true) ); } void ItemDocument::lowerZ( const ItemList &itemList ) { if ( m_zOrder.isEmpty() ) slotUpdateZOrdering(); if ( m_zOrder.isEmpty() ) return; IntItemMap::iterator previous = m_zOrder.begin(); IntItemMap::iterator end = m_zOrder.end(); for ( IntItemMap::iterator it = m_zOrder.begin(); it != end; ++it ) { Item * previousData = previous.value(); Item * currentData = it.value(); if ( currentData && previousData && itemList.contains(currentData) && !itemList.contains(previousData) ) { previous.value() = currentData; it.value() = previousData; } previous = it; } slotUpdateZOrdering(); } void ItemDocument::itemAdded( Item * ) { requestEvent( ItemDocument::ItemDocumentEvent::UpdateZOrdering ); } void ItemDocument::slotUpdateZOrdering() { ItemMap toAdd = m_itemList; IntItemMap newZOrder; int atLevel = 0; IntItemMap::iterator zEnd = m_zOrder.end(); for ( IntItemMap::iterator it = m_zOrder.begin(); it != zEnd; ++it ) { Item * item = it.value(); if (!item) continue; toAdd.remove( item->id() ); if ( !item->parentItem() && item->isMovable() ) newZOrder[atLevel++] = item; } ItemMap::iterator addEnd = toAdd.end(); for ( ItemMap::iterator it = toAdd.begin(); it != addEnd; ++it ) { Item * item = *it; if ( item->parentItem() || !item->isMovable() ) continue; newZOrder[atLevel++] = item; } m_zOrder = newZOrder; zEnd = m_zOrder.end(); for ( IntItemMap::iterator it = m_zOrder.begin(); it != zEnd; ++it ) it.value()->updateZ( it.key() ); } void ItemDocument::update( ) { ItemMap::iterator end = m_itemList.end(); for ( ItemMap::iterator it = m_itemList.begin(); it != end; ++it ) { if ( (*it)->contentChanged() ) (*it)->setChanged(); } } ItemList ItemDocument::itemList( ) const { ItemList l; ItemMap::const_iterator end = m_itemList.end(); for ( ItemMap::const_iterator it = m_itemList.begin(); it != end; ++it ) l << it.value(); return l; } //END class ItemDocument //BEGIN class CanvasTip CanvasTip::CanvasTip( ItemDocument *itemDocument, KtlQCanvas *qcanvas ) : KtlQCanvasRectangle( qcanvas ) { p_itemDocument = itemDocument; setZ( ICNDocument::Z::Tip ); } CanvasTip::~CanvasTip() { } void CanvasTip::displayVI( ECNode *node, const QPoint &pos ) { if ( !node || !updateVI() ) return; unsigned num = node->numPins(); m_v.resize(num); m_i.resize(num); for ( unsigned i = 0; i < num; i++ ) { if ( Pin * pin = node->pin(i) ) { m_v[i] = pin->voltage(); m_i[i] = pin->current(); } } display(pos); } void CanvasTip::displayVI( Connector *connector, const QPoint &pos ) { if ( !connector || !updateVI()) return; unsigned num = connector->numWires(); m_v.resize(num); m_i.resize(num); for ( unsigned i = 0; i < num; i++ ) { if ( Wire * wire = connector->wire(i) ) { m_v[i] = wire->voltage(); m_i[i] = std::abs(wire->current()); } } display(pos); } bool CanvasTip::updateVI() { CircuitDocument *circuitDocument = dynamic_cast(p_itemDocument); if ( !circuitDocument || !Simulator::self()->isSimulating() ) return false; circuitDocument->calculateConnectorCurrents(); return true; } void CanvasTip::display( const QPoint &pos ) { unsigned num = m_v.size(); for ( unsigned i = 0; i < num; i++ ) { if ( !std::isfinite(m_v[i]) || std::abs(m_v[i]) < 1e-9 ) m_v[i] = 0.; if ( !std::isfinite(m_i[i]) || std::abs(m_i[i]) < 1e-9 ) m_i[i] = 0.; } move( pos.x()+20, pos.y()+4 ); if ( num == 0 ) return; if ( num == 1 ) setText( displayText(0) ); else { QString text; for ( unsigned i = 0; i < num; i++ ) text += QString("%1: %2\n").arg( QString::number(i) ).arg( displayText(i) ); setText(text); } } QString CanvasTip::displayText( unsigned num ) const { if ( m_v.size() <= num ) return QString::null; return QString("%1%2V %3%4A") .arg( QString::number( m_v[num] / CNItem::getMultiplier(m_v[num]), 'g', 3 ) ) .arg( CNItem::getNumberMag( m_v[num] ) ) .arg( QString::number( m_i[num] / CNItem::getMultiplier(m_i[num]), 'g', 3 ) ) .arg( CNItem::getNumberMag( m_i[num] ) ); } void CanvasTip::draw( QPainter &p ) { CircuitDocument *circuitDocument = dynamic_cast(p_itemDocument); if ( !circuitDocument || !Simulator::self()->isSimulating() ) return; p.setBrush( QColor( 0xff, 0xff, 0xdc ) ); p.setPen( Qt::black ); p.drawRect( boundingRect() ); QRect textRect = boundingRect(); textRect.setLeft( textRect.left() + 3 ); textRect.setTop( textRect.top() + 1 ); p.drawText( textRect, 0, m_text ); } void CanvasTip::setText( const QString & text ) { m_text = text; canvas()->setChanged( boundingRect() ); QRect r = QFontMetrics( qApp->font() ).boundingRect( 0, 0, 0, 0, 0, m_text ); setSize( r.width() + 4, r.height() - 1 ); } //END class CanvasTip //BEGIN class Canvas Canvas::Canvas( ItemDocument *itemDocument, const char * name ) : KtlQCanvas( itemDocument, name ) { p_itemDocument = itemDocument; m_pMessageTimeout = new QTimer(this); connect( m_pMessageTimeout, SIGNAL(timeout()), this, SLOT(slotSetAllChanged()) ); } void Canvas::resize( const QRect & size ) { if ( rect() == size ) return; QRect oldSize = rect(); KtlQCanvas::resize( size ); emit resized( oldSize, size ); } void Canvas::setMessage( const QString & message ) { m_message = message; if ( message.isEmpty() ) { m_pMessageTimeout->stop(); } else { m_pMessageTimeout->setSingleShot(true); m_pMessageTimeout->start( 2000 /*, true */ ); } setAllChanged(); } void Canvas::drawBackground ( QPainter &p, const QRect & clip ) { KtlQCanvas::drawBackground( p, clip ); #if 0 const int scx = (int)((clip.left()-4)/8); const int ecx = (int)((clip.right()+4)/8); const int scy = (int)((clip.top()-4)/8); const int ecy = (int)((clip.bottom()+4)/8); ICNDocument * icnd = dynamic_cast(p_itemDocument); if ( !icnd ) return; Cells * c = icnd->cells(); if ( !c->haveCell( scx, scy ) || !c->haveCell( ecx, ecy ) ) return; for ( int x=scx; x<=ecx; x++ ) { for ( int y=scy; y<=ecy; y++ ) { const double score = c->cell( x, y ).CIpenalty + c->cell( x, y ).Cpenalty; int value = (int)std::log(score)*20; if ( value>255 ) value=255; else if (value<0 ) value=0; p.setBrush( QColor( 255, (255-value), (255-value) ) ); p.setPen( Qt::NoPen ); p.drawRect( (x*8), (y*8), 8, 8 ); } } #endif } void Canvas::drawForeground ( QPainter &p, const QRect & clip ) { KtlQCanvas::drawForeground( p, clip ); if ( !m_pMessageTimeout->isActive() ) return; // Following code stolen and adapted from amarok/src/playlist.cpp :) // Find out width of smallest view QSize minSize; const ViewList viewList = p_itemDocument->viewList(); ViewList::const_iterator end = viewList.end(); View * firstView = 0l; for ( ViewList::const_iterator it = viewList.begin(); it != end; ++it ) { if ( !*it ) continue; if ( !firstView ) { firstView = *it; minSize = (*it)->size(); } else minSize = minSize.boundedTo( (*it)->size() ); } if ( !firstView ) return; // Q3SimpleRichText * t = new Q3SimpleRichText( m_message, QApplication::font() ); QTextEdit * t = new QTextEdit( m_message ); t->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::QSizePolicy::Minimum); t->resize( t->sizeHint() ); // TODO fix resizing int w = t->width(); int h = t->height(); int x = rect().left() + 15; int y = rect().top() + 15; int b = 10; // text padding // if ( w+2*b >= minSize.width() || h+2*b >= minSize.height() ) // { // qWarning() << Q_FUNC_INFO << "size not good w=" << w << " h=" << h << "b=" << b << " minSize=" << minSize; // delete t; // return; // } //p.setBrush( firstView->colorGroup().background() ); // 2018.12.02 p.setBrush( firstView->palette().window() ); p.drawRoundRect( x, y, w+2*b, h+2*b, (8*200)/(w+2*b), (8*200)/(h+2*b) ); // t->draw( &p, x+b, y+b, QRect(), firstView->colorGroup() ); t->resize(w+2*b, h+2*b); t->render( &p, QPoint( x, y ) ); delete t; } void Canvas::update() { p_itemDocument->update(); KtlQCanvas::update(); } //END class Canvas #include "itemdocument.moc" diff --git a/src/ktlqt3support/CMakeLists.txt b/src/ktlqt3support/CMakeLists.txt index 0672f3cc..83fee909 100644 --- a/src/ktlqt3support/CMakeLists.txt +++ b/src/ktlqt3support/CMakeLists.txt @@ -1,8 +1,8 @@ SET(ktlqt3support_STAT_SRCS + ktlq3scrollview.cpp ktlq3polygonscanner.cpp - q3frame.cpp - q3scrollview.cpp + ktlq3frame.cpp ktlfindqobjectchild.cpp ) kde4_add_library(ktlqt3support STATIC ${ktlqt3support_STAT_SRCS}) diff --git a/src/ktlqt3support/q3frame.cpp b/src/ktlqt3support/ktlq3frame.cpp similarity index 88% rename from src/ktlqt3support/q3frame.cpp rename to src/ktlqt3support/ktlq3frame.cpp index de144dd1..8a89647e 100644 --- a/src/ktlqt3support/q3frame.cpp +++ b/src/ktlqt3support/ktlq3frame.cpp @@ -1,200 +1,200 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt3Support module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "q3frame.h" +#include "ktlq3frame.h" #include "qevent.h" #include "qpainter.h" QT_BEGIN_NAMESPACE -/*! \class Q3Frame +/*! \class KtlQ3Frame \compat */ /*! Creates a new frame with the given \a parent, object \a name, and with widget flags \a f. */ -Q3Frame::Q3Frame(QWidget* parent, const char* name, Qt::WindowFlags f) +KtlQ3Frame::KtlQ3Frame(QWidget* parent, const char* name, Qt::WindowFlags f) :QFrame(parent, f), marg(0) { if (name) setObjectName(QLatin1String(name)); setAttribute(Qt::WA_LayoutOnEntireRect); } /*! Destructs the frame. */ -Q3Frame::~Q3Frame() +KtlQ3Frame::~KtlQ3Frame() { } /*! Paints the frame (or part of the frame) that's necessary, depending on the \a event. */ -void Q3Frame::paintEvent(QPaintEvent * event) +void KtlQ3Frame::paintEvent(QPaintEvent * event) { QPainter paint(this); if (!contentsRect().contains(event->rect())) { paint.save(); paint.setClipRegion(event->region().intersected(frameRect())); drawFrame(&paint); paint.restore(); } if (event->rect().intersects(contentsRect())) { paint.setClipRegion(event->region().intersected(contentsRect())); drawContents(&paint); } } /*! - \fn void Q3Frame::drawContents(QPainter *painter) + \fn void KtlQ3Frame::drawContents(QPainter *painter) Virtual function that draws the contents of the frame on the given \a painter. The QPainter is already open when you get it, and you must leave it open. Painter \link QPainter::setWorldMatrix() transformations\endlink are switched off on entry. If you transform the painter, remember to take the frame into account and \link QPainter::resetXForm() reset transformation\endlink before returning. This function is reimplemented by subclasses that draw something inside the frame. It should only draw inside contentsRect(). The default function does nothing. \sa contentsRect(), QPainter::setClipRect() */ -void Q3Frame::drawContents(QPainter *) +void KtlQ3Frame::drawContents(QPainter *) { } /*! Draws the frame using the painter \a p and the current frame attributes and color group. The rectangle inside the frame is not affected. This function is virtual, but in general you do not need to reimplement it. If you do, note that the QPainter is already open and must remain open. \sa frameRect(), contentsRect(), drawContents(), frameStyle(), setPalette() */ -void Q3Frame::drawFrame(QPainter *p) +void KtlQ3Frame::drawFrame(QPainter *p) { QFrame::drawFrame(p); } /*! - \fn void Q3Frame::resizeEvent(QResizeEvent *event) + \fn void KtlQ3Frame::resizeEvent(QResizeEvent *event) This just calls frameChanged(); it does not make use of the \a event itself. */ -void Q3Frame::resizeEvent(QResizeEvent *e) +void KtlQ3Frame::resizeEvent(QResizeEvent *e) { if (e->size() == e->oldSize()) frameChanged(); } /*! Virtual function that is called when the frame style, line width or mid-line width changes. This function can be reimplemented by subclasses that need to know when the frame attributes change. */ -void Q3Frame::frameChanged() +void KtlQ3Frame::frameChanged() { } /*! - \property Q3Frame::margin + \property KtlQ3Frame::margin \brief the width of the margin The margin is the distance between the innermost pixel of the frame and the outermost pixel of contentsRect(). It is included in frameWidth(). The margin is filled according to backgroundMode(). The default value is 0. \sa lineWidth(), frameWidth() */ -void Q3Frame::setMargin(int w) +void KtlQ3Frame::setMargin(int w) { if (marg == w) return; marg = w; update(); frameChanged(); } /*! - \property Q3Frame::contentsRect + \property KtlQ3Frame::contentsRect \brief the frame's contents rectangle (including the margins) */ -QRect Q3Frame::contentsRect() const +QRect KtlQ3Frame::contentsRect() const { QRect cr(QFrame::contentsRect()); cr.adjust(marg, marg, -marg, -marg); return cr; } /*! Returns the width of the frame (including the margin). */ -int Q3Frame::frameWidth() const +int KtlQ3Frame::frameWidth() const { return QFrame::frameWidth() + marg; } QT_END_NAMESPACE diff --git a/src/ktlqt3support/q3frame.h b/src/ktlqt3support/ktlq3frame.h similarity index 88% rename from src/ktlqt3support/q3frame.h rename to src/ktlqt3support/ktlq3frame.h index bd755b18..10f60f71 100644 --- a/src/ktlqt3support/q3frame.h +++ b/src/ktlqt3support/ktlq3frame.h @@ -1,90 +1,90 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt3Support module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ -#ifndef Q3FRAME_H -#define Q3FRAME_H +#ifndef KTL_Q3FRAME_H +#define KTL_Q3FRAME_H #include -QT_BEGIN_HEADER +// QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE +// QT_BEGIN_NAMESPACE -QT_MODULE(Qt3SupportLight) +// QT_MODULE(Qt3SupportLight) -class Q_COMPAT_EXPORT Q3Frame : public QFrame +class KtlQ3Frame : public QFrame { Q_OBJECT Q_PROPERTY(int margin READ margin WRITE setMargin) Q_PROPERTY(QRect contentsRect READ contentsRect) public: - Q3Frame(QWidget* parent, const char* name = 0, Qt::WindowFlags f = 0); - ~Q3Frame(); + KtlQ3Frame(QWidget* parent, const char* name = 0, Qt::WindowFlags f = 0); + ~KtlQ3Frame(); #ifndef qdoc bool lineShapesOk() const { return true; } #endif int margin() const { return marg; } void setMargin(int); QRect contentsRect() const; int frameWidth() const; protected: void paintEvent(QPaintEvent *); void resizeEvent(QResizeEvent *); virtual void frameChanged(); virtual void drawFrame(QPainter *); virtual void drawContents(QPainter *); private: - Q_DISABLE_COPY(Q3Frame) + Q_DISABLE_COPY(KtlQ3Frame) int marg; }; -QT_END_NAMESPACE +// QT_END_NAMESPACE -QT_END_HEADER +// QT_END_HEADER -#endif // Q3FRAME_H +#endif // KTL_Q3FRAME_H diff --git a/src/ktlqt3support/q3scrollview.cpp b/src/ktlqt3support/ktlq3scrollview.cpp similarity index 82% rename from src/ktlqt3support/q3scrollview.cpp rename to src/ktlqt3support/ktlq3scrollview.cpp index 3b6f1941..b30ac6d5 100644 --- a/src/ktlqt3support/q3scrollview.cpp +++ b/src/ktlqt3support/ktlq3scrollview.cpp @@ -1,2856 +1,2832 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt3Support module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "ktlq3scrollview.h" + #include "qwidget.h" -#ifndef QT_NO_SCROLLVIEW #include "qscrollbar.h" #include "qpainter.h" #include "qpixmap.h" #include "qcursor.h" -#include "ktlqt3support/q3scrollview.h" #include "q3ptrdict.h" #include "qapplication.h" #include "qtimer.h" #include "qstyle.h" #include "q3ptrlist.h" #include "qevent.h" //#include "q3listview.h" // #ifdef Q_WS_MAC // 2018.10.18 - do not depend on internal headers // # include "private/qt_mac_p.h" // #endif -QT_BEGIN_NAMESPACE +// QT_BEGIN_NAMESPACE -using namespace Qt; +// using namespace Qt; static const int coord_limit = 4000; static const int autoscroll_margin = 16; static const int initialScrollTime = 30; static const int initialScrollAccel = 5; struct QSVChildRec { QSVChildRec(QWidget* c, int xx, int yy) : child(c), x(xx), y(yy) { } - void hideOrShow(Q3ScrollView* sv, QWidget* clipped_viewport); - void moveTo(Q3ScrollView* sv, int xx, int yy, QWidget* clipped_viewport) + void hideOrShow(KtlQ3ScrollView* sv, QWidget* clipped_viewport); + void moveTo(KtlQ3ScrollView* sv, int xx, int yy, QWidget* clipped_viewport) { if (x != xx || y != yy) { x = xx; y = yy; hideOrShow(sv,clipped_viewport); } } QWidget* child; int x, y; }; -void QSVChildRec::hideOrShow(Q3ScrollView* sv, QWidget* clipped_viewport) +void QSVChildRec::hideOrShow(KtlQ3ScrollView* sv, QWidget* clipped_viewport) { if (clipped_viewport) { if (x+child->width() < sv->contentsX()+clipped_viewport->x() || x > sv->contentsX()+clipped_viewport->width() || y+child->height() < sv->contentsY()+clipped_viewport->y() || y > sv->contentsY()+clipped_viewport->height()) { child->move(clipped_viewport->width(), clipped_viewport->height()); } else { child->move(x-sv->contentsX()-clipped_viewport->x(), y-sv->contentsY()-clipped_viewport->y()); } } else { child->move(x-sv->contentsX(), y-sv->contentsY()); } } -class QAbstractScrollAreaWidget : public QWidget -{ - Q_OBJECT - -public: - QAbstractScrollAreaWidget(Q3ScrollView* parent=0, const char* name=0, Qt::WindowFlags f = 0) - : QWidget(parent, f) - { - setObjectName(name); - setAutoFillBackground(true); - } -}; - -class QClipperWidget : public QWidget -{ - Q_OBJECT - -public: - QClipperWidget(QWidget * parent=0, const char * name=0, Qt::WindowFlags f=0) - : QWidget (parent,f) { - setObjectName(name); - } -}; - -QT_BEGIN_INCLUDE_NAMESPACE -#include "q3scrollview.moc" -QT_END_INCLUDE_NAMESPACE +// QT_BEGIN_INCLUDE_NAMESPACE +// #include "ktlq3scrollview.moc" +// QT_END_INCLUDE_NAMESPACE -class Q3ScrollViewData { +class KtlQ3ScrollViewData { public: - Q3ScrollViewData(Q3ScrollView* parent, int vpwflags) : + KtlQ3ScrollViewData(KtlQ3ScrollView* parent, int vpwflags) : hbar(new QScrollBar(Qt::Horizontal, parent /*, "qt_hbar"*/)), vbar(new QScrollBar(Qt::Vertical, parent /*, "qt_vbar" */)), - viewport(new QAbstractScrollAreaWidget(parent, "qt_viewport", QFlag(vpwflags))), + viewport(new KtlQAbstractScrollAreaWidget(parent, "qt_viewport", QFlag(vpwflags))), clipped_viewport(0), flags(vpwflags), vx(0), vy(0), vwidth(1), vheight(1), #ifndef QT_NO_DRAGANDDROP autoscroll_timer(parent /* , "scrollview autoscroll timer" */), drag_autoscroll(true), #endif scrollbar_timer(parent /*, "scrollview scrollbar timer" */), inresize(false), use_cached_size_hint(true) { hbar->setObjectName("qt_hbar"); vbar->setObjectName("qt_vbar"); #ifndef QT_NO_DRAGANDDROP autoscroll_timer.setObjectName("scrollview autoscroll timer"); #endif scrollbar_timer.setObjectName("scrollview scrollbar timer"); l_marg = r_marg = t_marg = b_marg = 0; viewport->ensurePolished(); - vMode = Q3ScrollView::Auto; - hMode = Q3ScrollView::Auto; + vMode = KtlQ3ScrollView::Auto; + hMode = KtlQ3ScrollView::Auto; corner = 0; // vbar->setSteps(20, 1/*set later*/); vbar->setSingleStep(20); vbar->setPageStep(1); //hbar->setSteps(20, 1/*set later*/); hbar->setSingleStep(20); hbar->setPageStep(1); - policy = Q3ScrollView::Default; + policy = KtlQ3ScrollView::Default; signal_choke = false; static_bg = false; fake_scroll = false; hbarPressed = false; vbarPressed = false; hbar->setLayoutDirection(Qt::LeftToRight); } - ~Q3ScrollViewData(); + ~KtlQ3ScrollViewData(); QSVChildRec* rec(QWidget* w) { return childDict.find(w); } QSVChildRec* ancestorRec(QWidget* w); QSVChildRec* addChildRec(QWidget* w, int x, int y) { QSVChildRec *r = new QSVChildRec(w,x,y); children.append(r); childDict.insert(w, r); return r; } void deleteChildRec(QSVChildRec* r) { childDict.remove(r->child); children.removeRef(r); delete r; } - void hideOrShowAll(Q3ScrollView* sv, bool isScroll = false); + void hideOrShowAll(KtlQ3ScrollView* sv, bool isScroll = false); void moveAllBy(int dx, int dy); bool anyVisibleChildren(); - void autoMove(Q3ScrollView* sv); - void autoResize(Q3ScrollView* sv); - void autoResizeHint(Q3ScrollView* sv); + void autoMove(KtlQ3ScrollView* sv); + void autoResize(KtlQ3ScrollView* sv); + void autoResizeHint(KtlQ3ScrollView* sv); void viewportResized(int w, int h); QScrollBar* hbar; QScrollBar* vbar; bool hbarPressed; bool vbarPressed; - QAbstractScrollAreaWidget* viewport; - QClipperWidget* clipped_viewport; + KtlQAbstractScrollAreaWidget* viewport; + KtlQClipperWidget* clipped_viewport; int flags; Q3PtrList children; Q3PtrDict childDict; QWidget* corner; int vx, vy, vwidth, vheight; // for drawContents-style usage int l_marg, r_marg, t_marg, b_marg; - Q3ScrollView::ResizePolicy policy; - Q3ScrollView::ScrollBarMode vMode; - Q3ScrollView::ScrollBarMode hMode; + KtlQ3ScrollView::ResizePolicy policy; + KtlQ3ScrollView::ScrollBarMode vMode; + KtlQ3ScrollView::ScrollBarMode hMode; #ifndef QT_NO_DRAGANDDROP QPoint cpDragStart; QTimer autoscroll_timer; int autoscroll_time; int autoscroll_accel; bool drag_autoscroll; #endif QTimer scrollbar_timer; uint static_bg : 1; uint fake_scroll : 1; // This variable allows ensureVisible to move the contents then // update both the sliders. Otherwise, updating the sliders would // cause two image scrolls, creating ugly flashing. // uint signal_choke : 1; // This variables indicates in updateScrollBars() that we are // in a resizeEvent() and thus don't want to flash scroll bars uint inresize : 1; uint use_cached_size_hint : 1; QSize cachedSizeHint; inline int contentsX() const { return -vx; } inline int contentsY() const { return -vy; } inline int contentsWidth() const { return vwidth; } }; -inline Q3ScrollViewData::~Q3ScrollViewData() +inline KtlQ3ScrollViewData::~KtlQ3ScrollViewData() { children.setAutoDelete(true); } -QSVChildRec* Q3ScrollViewData::ancestorRec(QWidget* w) +QSVChildRec* KtlQ3ScrollViewData::ancestorRec(QWidget* w) { if (clipped_viewport) { while (w->parentWidget() != clipped_viewport) { w = w->parentWidget(); if (!w) return 0; } } else { while (w->parentWidget() != viewport) { w = w->parentWidget(); if (!w) return 0; } } return rec(w); } -void Q3ScrollViewData::hideOrShowAll(Q3ScrollView* sv, bool isScroll) +void KtlQ3ScrollViewData::hideOrShowAll(KtlQ3ScrollView* sv, bool isScroll) { if (!clipped_viewport) return; if (clipped_viewport->x() <= 0 && clipped_viewport->y() <= 0 && clipped_viewport->width()+clipped_viewport->x() >= viewport->width() && clipped_viewport->height()+clipped_viewport->y() >= viewport->height()) { // clipped_viewport still covers viewport if(static_bg) { //clipped_viewport->repaint(true); // 2018.11.30 clipped_viewport->repaint(); } else if ((!isScroll && !clipped_viewport->testAttribute(Qt::WA_StaticContents)) || static_bg) clipped_viewport->update(); } else { // Re-center int nx = (viewport->width() - clipped_viewport->width()) / 2; int ny = (viewport->height() - clipped_viewport->height()) / 2; clipped_viewport->move(nx,ny); clipped_viewport->update(); } for (QSVChildRec *r = children.first(); r; r=children.next()) { r->hideOrShow(sv, clipped_viewport); } } -void Q3ScrollViewData::moveAllBy(int dx, int dy) +void KtlQ3ScrollViewData::moveAllBy(int dx, int dy) { if (clipped_viewport && !static_bg) { clipped_viewport->move(clipped_viewport->x()+dx, clipped_viewport->y()+dy); } else { for (QSVChildRec *r = children.first(); r; r=children.next()) { r->child->move(r->child->x()+dx,r->child->y()+dy); } if (static_bg) { //viewport->repaint(true); // 2018.11.30 viewport->repaint(); } } } -bool Q3ScrollViewData::anyVisibleChildren() +bool KtlQ3ScrollViewData::anyVisibleChildren() { for (QSVChildRec *r = children.first(); r; r=children.next()) { if (r->child->isVisible()) return true; } return false; } -void Q3ScrollViewData::autoMove(Q3ScrollView* sv) +void KtlQ3ScrollViewData::autoMove(KtlQ3ScrollView* sv) { - if (policy == Q3ScrollView::AutoOne) { + if (policy == KtlQ3ScrollView::AutoOne) { QSVChildRec* r = children.first(); if (r) sv->setContentsPos(-r->child->x(),-r->child->y()); } } -void Q3ScrollViewData::autoResize(Q3ScrollView* sv) +void KtlQ3ScrollViewData::autoResize(KtlQ3ScrollView* sv) { - if (policy == Q3ScrollView::AutoOne) { + if (policy == KtlQ3ScrollView::AutoOne) { QSVChildRec* r = children.first(); if (r) sv->resizeContents(r->child->width(),r->child->height()); } } -void Q3ScrollViewData::autoResizeHint(Q3ScrollView* sv) +void KtlQ3ScrollViewData::autoResizeHint(KtlQ3ScrollView* sv) { - if (policy == Q3ScrollView::AutoOne) { + if (policy == KtlQ3ScrollView::AutoOne) { QSVChildRec* r = children.first(); if (r) { QSize s = r->child->sizeHint(); if (s.isValid()) r->child->resize(s); } - } else if (policy == Q3ScrollView::AutoOneFit) { + } else if (policy == KtlQ3ScrollView::AutoOneFit) { QSVChildRec* r = children.first(); if (r) { QSize sh = r->child->sizeHint(); sh = sh.boundedTo(r->child->maximumSize()); sv->resizeContents(sh.width(), sh.height()); } } } -void Q3ScrollViewData::viewportResized(int w, int h) +void KtlQ3ScrollViewData::viewportResized(int w, int h) { - if (policy == Q3ScrollView::AutoOneFit) { + if (policy == KtlQ3ScrollView::AutoOneFit) { QSVChildRec* r = children.first(); if (r) { QSize sh = r->child->sizeHint(); sh = sh.boundedTo(r->child->maximumSize()); r->child->resize(QMAX(w,sh.width()), QMAX(h,sh.height())); } } } /*! - \class Q3ScrollView - \brief The Q3ScrollView widget provides a scrolling area with on-demand scroll bars. + \class KtlQ3ScrollView + \brief The KtlQ3ScrollView widget provides a scrolling area with on-demand scroll bars. \compat - The Q3ScrollView is a large canvas - potentially larger than the + The KtlQ3ScrollView is a large canvas - potentially larger than the coordinate system normally supported by the underlying window system. This is important because it is quite easy to go beyond these limitations (e.g. many web pages are more than 32000 pixels - high). Additionally, the Q3ScrollView can have QWidgets positioned + high). Additionally, the KtlQ3ScrollView can have QWidgets positioned on it that scroll around with the drawn content. These sub-widgets can also have positions outside the normal coordinate range (but they are still limited in size). - To provide content for the widget, inherit from Q3ScrollView, + To provide content for the widget, inherit from KtlQ3ScrollView, reimplement drawContents() and use resizeContents() to set the size of the viewed area. Use addChild() and moveChild() to position widgets on the view. - To use Q3ScrollView effectively it is important to understand its + To use KtlQ3ScrollView effectively it is important to understand its widget structure in the three styles of use: a single large child widget, a large panning area with some widgets and a large panning area with many widgets. \section1 Using One Big Widget \img qscrollview-vp2.png - The first, simplest usage of Q3ScrollView (depicted above), is + The first, simplest usage of KtlQ3ScrollView (depicted above), is appropriate for scrolling areas that are never more than about 4000 pixels in either dimension (this is about the maximum reliable size on X11 servers). In this usage, you just make one - large child in the Q3ScrollView. The child should be a child of the + large child in the KtlQ3ScrollView. The child should be a child of the viewport() of the scrollview and be added with addChild(): \snippet doc/src/snippets/code/src_qt3support_widgets_q3scrollview.cpp 0 You can go on to add arbitrary child widgets to the single child in the scrollview as you would with any widget: \snippet doc/src/snippets/code/src_qt3support_widgets_q3scrollview.cpp 1 - Here the Q3ScrollView has four children: the viewport(), the + Here the KtlQ3ScrollView has four children: the viewport(), the verticalScrollBar(), the horizontalScrollBar() and a small cornerWidget(). The viewport() has one child: the QWidget. The QWidget has the three QLabel objects as child widgets. When the view is scrolled, the QWidget is moved; its children move with it as child widgets normally do. \section1 Using a Very Big View with Some Widgets \img qscrollview-vp.png - The second usage of Q3ScrollView (depicted above) is appropriate + The second usage of KtlQ3ScrollView (depicted above) is appropriate when few, if any, widgets are on a very large scrolling area that is potentially larger than 4000 pixels in either dimension. In this usage you call resizeContents() to set the size of the area and reimplement drawContents() to paint the contents. You may also add some widgets by making them children of the viewport() and adding them with addChild() (this is the same as the process for the single large widget in the previous example): \snippet doc/src/snippets/code/src_qt3support_widgets_q3scrollview.cpp 2 - Here, the Q3ScrollView has the same four children: the viewport(), + Here, the KtlQ3ScrollView has the same four children: the viewport(), the verticalScrollBar(), the horizontalScrollBar() and a small cornerWidget(). The viewport() has the three QLabel objects as child widgets. When the view is scrolled, the scrollview moves the child widgets individually. \section1 Using a Very Big View with Many Widgets \img qscrollview-cl.png - The final usage of Q3ScrollView (depicted above) is appropriate + The final usage of KtlQ3ScrollView (depicted above) is appropriate when many widgets are on a very large scrolling area that is potentially larger than 4000 pixels in either dimension. In this usage you call resizeContents() to set the size of the area and reimplement drawContents() to paint the contents. You then call enableClipper(true) and add widgets, again by making them children of the viewport(), and adding them with addChild(): \snippet doc/src/snippets/code/src_qt3support_widgets_q3scrollview.cpp 3 - Here, the Q3ScrollView has four children: the clipper() (not the + Here, the KtlQ3ScrollView has four children: the clipper() (not the viewport() this time), the verticalScrollBar(), the horizontalScrollBar() and a small cornerWidget(). The clipper() has one child: the viewport(). The viewport() has the same three labels as child widgets. When the view is scrolled the viewport() is moved; its children move with it as child widgets normally do. \target allviews \section1 Details Relevant for All Views Normally you will use the first or third method if you want any child widgets in the view. Note that the widget you see in the scrolled area is the - viewport() widget, not the Q3ScrollView itself. So to turn mouse + viewport() widget, not the KtlQ3ScrollView itself. So to turn mouse tracking on, for example, use viewport()->setMouseTracking(true). To enable drag-and-drop, you would setAcceptDrops(true) on the - Q3ScrollView (because drag-and-drop events propagate to the + KtlQ3ScrollView (because drag-and-drop events propagate to the parent). But to work out the logical position in the view, you would need to map the drop co-ordinate from being relative to the - Q3ScrollView to being relative to the contents; use the function + KtlQ3ScrollView to being relative to the contents; use the function viewportToContents() for this. To handle mouse events on the scrolling area, subclass scrollview as you would subclass other widgets, but rather than reimplementing mousePressEvent(), reimplement contentsMousePressEvent() instead. The contents specific event handlers provide translated events in the coordinate system of the scrollview. If you reimplement mousePressEvent(), you'll get - called only when part of the Q3ScrollView is clicked: and the only + called only when part of the KtlQ3ScrollView is clicked: and the only such part is the "corner" (if you don't set a cornerWidget()) and the frame; everything else is covered up by the viewport, clipper or scroll bars. - When you construct a Q3ScrollView, some of the window flags apply + When you construct a KtlQ3ScrollView, some of the window flags apply to the viewport() instead of being sent to the QWidget constructor - for the Q3ScrollView. + for the KtlQ3ScrollView. \list \i An image-manipulation widget would use \c WNoAutoErase|WStaticContents because the widget draws all pixels itself, and when its size increases, it only needs a paint event for the new part because the old part remains unchanged. \i A scrolling game widget in which the background scrolls as the characters move might use \c WNoAutoErase (in addition to \c WStaticContents) so that the window system background does not flash in and out during scrolling. \i A word processing widget might use \c WNoAutoErase and repaint itself line by line to get a less-flickery resizing. If the widget is in a mode in which no text justification can take place, it might use \c WStaticContents too, so that it would only get a repaint for the newly visible parts. \endlist Child widgets may be moved using addChild() or moveChild(). Use childX() and childY() to get the position of a child widget. A widget may be placed in the corner between the vertical and horizontal scroll bars with setCornerWidget(). You can get access to the scroll bars using horizontalScrollBar() and verticalScrollBar(), and to the viewport with viewport(). The scroll view can be scrolled using scrollBy(), ensureVisible(), setContentsPos() or center(). The visible area is given by visibleWidth() and visibleHeight(), and the contents area by contentsWidth() and contentsHeight(). The contents may be repainted using one of the repaintContents() or updateContents() functions. Coordinate conversion is provided by contentsToViewport() and viewportToContents(). The contentsMoving() signal is emitted just before the contents are moved to a new position. - \warning Q3ScrollView currently does not erase the background when + \warning KtlQ3ScrollView currently does not erase the background when resized, i.e. you must always clear the background manually in scrollview subclasses. This will change in a future version of Qt and we recommend specifying the \c WNoAutoErase flag explicitly. */ /*! - \enum Q3ScrollView::ResizePolicy + \enum KtlQ3ScrollView::ResizePolicy - This enum type is used to control a Q3ScrollView's reaction to + This enum type is used to control a KtlQ3ScrollView's reaction to resize events. - \value Default the Q3ScrollView selects one of the other settings - automatically when it has to. In this version of Qt, Q3ScrollView + \value Default the KtlQ3ScrollView selects one of the other settings + automatically when it has to. In this version of Qt, KtlQ3ScrollView changes to \c Manual if you resize the contents with resizeContents() and to \c AutoOne if a child is added. \value Manual the contents stays the size set by resizeContents(). \value AutoOne if there is only one child widget the contents stays the size of that widget. Otherwise the behavior is undefined. \value AutoOneFit if there is only one child widget the contents stays the size of that widget's sizeHint(). If the scrollview is resized larger than the child's sizeHint(), the child will be resized to fit. If there is more than one child, the behavior is undefined. */ //#### The widget will be resized to its sizeHint() when a LayoutHint event //#### is received /*! - Constructs a Q3ScrollView called \a name with parent \a parent and + Constructs a KtlQ3ScrollView called \a name with parent \a parent and widget flags \a f. The widget flags \c WStaticContents, \c WNoAutoErase and \c WPaintClever are propagated to the viewport() widget. The other widget flags are propagated to the parent constructor as usual. */ -Q3ScrollView::Q3ScrollView(QWidget *parent, const char *name, Qt::WindowFlags f) : - Q3Frame(parent, name, f & (~WStaticContents) & (~WNoAutoErase) & (~WResizeNoErase)) +KtlQ3ScrollView::KtlQ3ScrollView(QWidget *parent, const char *name, Qt::WindowFlags f) : + KtlQ3Frame(parent, name, f & (~Qt::WStaticContents) & (~Qt::WNoAutoErase) & (~Qt::WResizeNoErase)) { - WindowFlags flags = WResizeNoErase | (f&WPaintClever) | (f&WRepaintNoErase) | (f&WStaticContents); - d = new Q3ScrollViewData(this, flags); + Qt::WindowFlags flags = Qt::WResizeNoErase | (f&Qt::WPaintClever) | (f&Qt::WRepaintNoErase) | (f&Qt::WStaticContents); + d = new KtlQ3ScrollViewData(this, flags); #ifndef QT_NO_DRAGANDDROP connect(&d->autoscroll_timer, SIGNAL(timeout()), this, SLOT(doDragAutoScroll())); #endif connect(d->hbar, SIGNAL(valueChanged(int)), this, SLOT(hslide(int))); connect(d->vbar, SIGNAL(valueChanged(int)), this, SLOT(vslide(int))); connect(d->hbar, SIGNAL(sliderPressed()), this, SLOT(hbarIsPressed())); connect(d->hbar, SIGNAL(sliderReleased()), this, SLOT(hbarIsReleased())); connect(d->vbar, SIGNAL(sliderPressed()), this, SLOT(vbarIsPressed())); connect(d->vbar, SIGNAL(sliderReleased()), this, SLOT(vbarIsReleased())); d->viewport->installEventFilter(this); connect(&d->scrollbar_timer, SIGNAL(timeout()), this, SLOT(updateScrollBars())); - setFrameStyle(Q3Frame::StyledPanel | Q3Frame::Sunken); + setFrameStyle(KtlQ3Frame::StyledPanel | KtlQ3Frame::Sunken); setLineWidth(style()->pixelMetric(QStyle::PM_DefaultFrameWidth)); setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); } /*! - Destroys the Q3ScrollView. Any children added with addChild() will + Destroys the KtlQ3ScrollView. Any children added with addChild() will be deleted. */ -Q3ScrollView::~Q3ScrollView() +KtlQ3ScrollView::~KtlQ3ScrollView() { // Be careful not to get all those useless events... if (d->clipped_viewport) d->clipped_viewport->removeEventFilter(this); else d->viewport->removeEventFilter(this); // order is important // ~QWidget may cause a WM_ERASEBKGND on Windows delete d->vbar; d->vbar = 0; delete d->hbar; d->hbar = 0; delete d->viewport; d->viewport = 0; delete d; d = 0; } /*! - \fn void Q3ScrollView::horizontalSliderPressed() + \fn void KtlQ3ScrollView::horizontalSliderPressed() This signal is emitted whenever the user presses the horizontal slider. */ /*! - \fn void Q3ScrollView::horizontalSliderReleased() + \fn void KtlQ3ScrollView::horizontalSliderReleased() This signal is emitted whenever the user releases the horizontal slider. */ /*! - \fn void Q3ScrollView::verticalSliderPressed() + \fn void KtlQ3ScrollView::verticalSliderPressed() This signal is emitted whenever the user presses the vertical slider. */ /*! - \fn void Q3ScrollView::verticalSliderReleased() + \fn void KtlQ3ScrollView::verticalSliderReleased() This signal is emitted whenever the user releases the vertical slider. */ -void Q3ScrollView::hbarIsPressed() +void KtlQ3ScrollView::hbarIsPressed() { d->hbarPressed = true; emit(horizontalSliderPressed()); } -void Q3ScrollView::hbarIsReleased() +void KtlQ3ScrollView::hbarIsReleased() { d->hbarPressed = false; emit(horizontalSliderReleased()); } /*! Returns true if horizontal slider is pressed by user; otherwise returns false. */ -bool Q3ScrollView::isHorizontalSliderPressed() +bool KtlQ3ScrollView::isHorizontalSliderPressed() { return d->hbarPressed; } -void Q3ScrollView::vbarIsPressed() +void KtlQ3ScrollView::vbarIsPressed() { d->vbarPressed = true; emit(verticalSliderPressed()); } -void Q3ScrollView::vbarIsReleased() +void KtlQ3ScrollView::vbarIsReleased() { d->vbarPressed = false; emit(verticalSliderReleased()); } /*! Returns true if vertical slider is pressed by user; otherwise returns false. */ -bool Q3ScrollView::isVerticalSliderPressed() +bool KtlQ3ScrollView::isVerticalSliderPressed() { return d->vbarPressed; } /*! \internal */ -void Q3ScrollView::styleChange(QStyle& old) +void KtlQ3ScrollView::styleChange(QStyle& old) { QWidget::styleChange(old); updateScrollBars(); d->cachedSizeHint = QSize(); } /*! \internal */ -void Q3ScrollView::fontChange(const QFont &old) +void KtlQ3ScrollView::fontChange(const QFont &old) { QWidget::fontChange(old); updateScrollBars(); d->cachedSizeHint = QSize(); } -void Q3ScrollView::hslide(int pos) +void KtlQ3ScrollView::hslide(int pos) { if (!d->signal_choke) { moveContents(-pos, -d->contentsY()); QApplication::syncX(); } } -void Q3ScrollView::vslide(int pos) +void KtlQ3ScrollView::vslide(int pos) { if (!d->signal_choke) { moveContents(-d->contentsX(), -pos); QApplication::syncX(); } } /*! Called when the horizontal scroll bar geometry changes. This is provided as a protected function so that subclasses can do interesting things such as providing extra buttons in some of the space normally used by the scroll bars. The default implementation simply gives all the space to \a hbar. The new geometry is given by \a x, \a y, \a w and \a h. \sa setVBarGeometry() */ -void Q3ScrollView::setHBarGeometry(QScrollBar& hbar, +void KtlQ3ScrollView::setHBarGeometry(QScrollBar& hbar, int x, int y, int w, int h) { hbar.setGeometry(x, y, w, h); } /*! Called when the vertical scroll bar geometry changes. This is provided as a protected function so that subclasses can do interesting things such as providing extra buttons in some of the space normally used by the scroll bars. The default implementation simply gives all the space to \a vbar. The new geometry is given by \a x, \a y, \a w and \a h. \sa setHBarGeometry() */ -void Q3ScrollView::setVBarGeometry(QScrollBar& vbar, +void KtlQ3ScrollView::setVBarGeometry(QScrollBar& vbar, int x, int y, int w, int h) { vbar.setGeometry(x, y, w, h); } /*! Returns the viewport size for size (\a x, \a y). The viewport size depends on (\a x, \a y) (the size of the contents), the size of this widget and the modes of the horizontal and vertical scroll bars. This function permits widgets that can trade vertical and horizontal space for each other to control scroll bar appearance better. For example, a word processor or web browser can control the width of the right margin accurately, whether or not there needs to be a vertical scroll bar. */ -QSize Q3ScrollView::viewportSize(int x, int y) const +QSize KtlQ3ScrollView::viewportSize(int x, int y) const { int fw = frameWidth(); int lmarg = fw+d->l_marg; int rmarg = fw+d->r_marg; int tmarg = fw+d->t_marg; int bmarg = fw+d->b_marg; int w = width(); int h = height(); bool needh, needv; bool showh, showv; int hsbExt = horizontalScrollBar()->sizeHint().height(); int vsbExt = verticalScrollBar()->sizeHint().width(); if (d->policy != AutoOne || d->anyVisibleChildren()) { // Do we definitely need the scroll bar? needh = w-lmarg-rmarg < x; needv = h-tmarg-bmarg < y; // Do we intend to show the scroll bar? if (d->hMode == AlwaysOn) showh = true; else if (d->hMode == AlwaysOff) showh = false; else showh = needh; if (d->vMode == AlwaysOn) showv = true; else if (d->vMode == AlwaysOff) showv = false; else showv = needv; // Given other scroll bar will be shown, NOW do we need one? if (showh && h-vsbExt-tmarg-bmarg < y) { if (d->vMode == Auto) showv=true; } if (showv && w-hsbExt-lmarg-rmarg < x) { if (d->hMode == Auto) showh=true; } } else { // Scroll bars not needed, only show scroll bar that are always on. showh = d->hMode == AlwaysOn; showv = d->vMode == AlwaysOn; } return QSize(w-lmarg-rmarg - (showv ? vsbExt : 0), h-tmarg-bmarg - (showh ? hsbExt : 0)); } /*! Updates scroll bars: all possibilities are considered. You should never need to call this in your code. */ -void Q3ScrollView::updateScrollBars() +void KtlQ3ScrollView::updateScrollBars() { if(!horizontalScrollBar() && !verticalScrollBar()) return; // I support this should use viewportSize()... but it needs // so many of the temporary variables from viewportSize. hm. int fw = frameWidth(); int lmarg = fw+d->l_marg; int rmarg = fw+d->r_marg; int tmarg = fw+d->t_marg; int bmarg = fw+d->b_marg; int w = width(); int h = height(); int portw, porth; bool needh; bool needv; bool showh; bool showv; bool showc = false; int hsbExt = horizontalScrollBar()->sizeHint().height(); int vsbExt = verticalScrollBar()->sizeHint().width(); QSize oldVisibleSize(visibleWidth(), visibleHeight()); if (d->policy != AutoOne || d->anyVisibleChildren()) { // Do we definitely need the scroll bar? needh = w-lmarg-rmarg < d->contentsWidth(); if (d->inresize) needh = !horizontalScrollBar()->isHidden(); needv = h-tmarg-bmarg < contentsHeight(); // Do we intend to show the scroll bar? if (d->hMode == AlwaysOn) showh = true; else if (d->hMode == AlwaysOff) showh = false; else showh = needh; if (d->vMode == AlwaysOn) showv = true; else if (d->vMode == AlwaysOff) showv = false; else showv = needv; #ifdef Q_WS_MAC bool mac_need_scroll = false; if(!parentWidget()) { mac_need_scroll = true; } else { QWidget *tlw = window(); // #ifndef QT_MAC_USE_COCOA // 2018.10.18 - do not depend on internal headers // QPoint tlw_br = QPoint(tlw->width(), tlw->height()), // my_br = qt_mac_posInWindow(this) + QPoint(w, h); // if(my_br.x() >= tlw_br.x() - 3 && my_br.y() >= tlw_br.y() - 3) // #endif mac_need_scroll = true; } if(mac_need_scroll) { // #ifndef QT_MAC_USE_COCOA // 2018.10.18 - do not depend on internal headers // WindowAttributes attr; // GetWindowAttributes((WindowPtr)handle(), &attr); // mac_need_scroll = (attr & kWindowResizableAttribute); // #endif } if(mac_need_scroll) { showc = true; if(d->vMode == Auto) showv = true; if(d->hMode == Auto) showh = true; } #endif // Given other scroll bar will be shown, NOW do we need one? if (showh && h-vsbExt-tmarg-bmarg < contentsHeight()) { needv=true; if (d->vMode == Auto) showv=true; } if (showv && !d->inresize && w-hsbExt-lmarg-rmarg < d->contentsWidth()) { needh=true; if (d->hMode == Auto) showh=true; } } else { // Scrollbars not needed, only show scroll bar that are always on. needh = needv = false; showh = d->hMode == AlwaysOn; showv = d->vMode == AlwaysOn; } bool sc = d->signal_choke; d->signal_choke=true; // Hide unneeded scroll bar, calculate viewport size if (showh) { porth=h-hsbExt-tmarg-bmarg; } else { if (!needh) d->hbar->setValue(0); d->hbar->hide(); porth=h-tmarg-bmarg; } if (showv) { portw=w-vsbExt-lmarg-rmarg; } else { if (!needv) d->vbar->setValue(0); d->vbar->hide(); portw=w-lmarg-rmarg; } // Configure scroll bars that we will show if (needv) { d->vbar->setRange(0, contentsHeight()-porth); - //d->vbar->setSteps(Q3ScrollView::d->vbar->lineStep(), porth); // 2018.11.30 - d->vbar->setSingleStep(Q3ScrollView::d->vbar->singleStep()); + //d->vbar->setSteps(KtlQ3ScrollView::d->vbar->lineStep(), porth); // 2018.11.30 + d->vbar->setSingleStep(KtlQ3ScrollView::d->vbar->singleStep()); d->vbar->setPageStep(porth); } else { d->vbar->setRange(0, 0); } if (needh) { d->hbar->setRange(0, QMAX(0, d->contentsWidth()-portw)); - //d->hbar->setSteps(Q3ScrollView::d->hbar->lineStep(), portw); // 2018.11.30 - d->hbar->setSingleStep(Q3ScrollView::d->hbar->singleStep()); + //d->hbar->setSteps(KtlQ3ScrollView::d->hbar->lineStep(), portw); // 2018.11.30 + d->hbar->setSingleStep(KtlQ3ScrollView::d->hbar->singleStep()); d->hbar->setPageStep(portw); } else { d->hbar->setRange(0, 0); } // Position the scroll bars, viewport and corner widget. int bottom; bool reverse = QApplication::layoutDirection() == Qt::RightToLeft; int xoffset = (reverse && (showv || cornerWidget())) ? vsbExt : 0; int xpos = reverse ? 0 : w - vsbExt; bool frameContentsOnly = style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents); if(! frameContentsOnly) { if (reverse) xpos += fw; else xpos -= fw; } if (showh) { int right = (showc || showv || cornerWidget()) ? w-vsbExt : w; if (! frameContentsOnly) setHBarGeometry(*d->hbar, fw + xoffset, h-hsbExt-fw, right-fw-fw, hsbExt); else setHBarGeometry(*d->hbar, 0 + xoffset, h-hsbExt, right, hsbExt); bottom=h-hsbExt; } else { bottom=h; } if (showv) { clipper()->setGeometry(lmarg + xoffset, tmarg, w-vsbExt-lmarg-rmarg, bottom-tmarg-bmarg); d->viewportResized(w-vsbExt-lmarg-rmarg, bottom-tmarg-bmarg); if (! frameContentsOnly) changeFrameRect(QRect(0, 0, w, h)); else changeFrameRect(QRect(xoffset, 0, w-vsbExt, bottom)); if (showc || cornerWidget()) { if (! frameContentsOnly) setVBarGeometry(*d->vbar, xpos, fw, vsbExt, h-hsbExt-fw-fw); else setVBarGeometry(*d->vbar, xpos, 0, vsbExt, h-hsbExt); } else { if (! frameContentsOnly) setVBarGeometry(*d->vbar, xpos, fw, vsbExt, bottom-fw-fw); else setVBarGeometry(*d->vbar, xpos, 0, vsbExt, bottom); } } else { if (! frameContentsOnly) changeFrameRect(QRect(0, 0, w, h)); else changeFrameRect(QRect(0, 0, w, bottom)); clipper()->setGeometry(lmarg, tmarg, w-lmarg-rmarg, bottom-tmarg-bmarg); d->viewportResized(w-lmarg-rmarg, bottom-tmarg-bmarg); } QWidget *corner = d->corner; if (d->corner) { if (! frameContentsOnly) corner->setGeometry(xpos, h-hsbExt-fw, vsbExt, hsbExt); else corner->setGeometry(xpos, h-hsbExt, vsbExt, hsbExt); } d->signal_choke=sc; if (d->contentsX()+visibleWidth() > d->contentsWidth()) { int x; #if 0 if (reverse) x =QMIN(0,d->contentsWidth()-visibleWidth()); else #endif x =QMAX(0,d->contentsWidth()-visibleWidth()); d->hbar->setValue(x); // Do it even if it is recursive moveContents(-x, -d->contentsY()); } if (d->contentsY()+visibleHeight() > contentsHeight()) { int y=QMAX(0,contentsHeight()-visibleHeight()); d->vbar->setValue(y); // Do it even if it is recursive moveContents(-d->contentsX(), -y); } // Finally, show the scroll bars if (showh && (d->hbar->isHidden() || !d->hbar->isVisible())) d->hbar->show(); if (showv && (d->vbar->isHidden() || !d->vbar->isVisible())) d->vbar->show(); d->signal_choke=true; d->vbar->setValue(d->contentsY()); d->hbar->setValue(d->contentsX()); d->signal_choke=false; QSize newVisibleSize(visibleWidth(), visibleHeight()); if (d->clipped_viewport && oldVisibleSize != newVisibleSize) { QResizeEvent e(newVisibleSize, oldVisibleSize); viewportResizeEvent(&e); } } /*! \reimp */ -void Q3ScrollView::setVisible(bool visible) +void KtlQ3ScrollView::setVisible(bool visible) { if (visible && !isVisible()) { QWidget::setVisible(visible); updateScrollBars(); d->hideOrShowAll(this); } else { QWidget::setVisible(visible); } } /*! \internal */ -void Q3ScrollView::resize(int w, int h) +void KtlQ3ScrollView::resize(int w, int h) { QWidget::resize(w, h); } /*! \internal */ -void Q3ScrollView::resize(const QSize& s) +void KtlQ3ScrollView::resize(const QSize& s) { resize(s.width(), s.height()); } /*! \reimp */ -void Q3ScrollView::resizeEvent(QResizeEvent* event) +void KtlQ3ScrollView::resizeEvent(QResizeEvent* event) { - Q3Frame::resizeEvent(event); + KtlQ3Frame::resizeEvent(event); #if 0 if (QApplication::reverseLayout()) { d->fake_scroll = true; scrollBy(-event->size().width() + event->oldSize().width(), 0); d->fake_scroll = false; } #endif bool inresize = d->inresize; d->inresize = true; updateScrollBars(); d->inresize = inresize; //d->scrollbar_timer.start(0, true); // 2018.11.30 d->scrollbar_timer.setSingleShot(true); d->scrollbar_timer.start(0); d->hideOrShowAll(this); } /*! \reimp */ -void Q3ScrollView::mousePressEvent(QMouseEvent * e) +void KtlQ3ScrollView::mousePressEvent(QMouseEvent * e) { e->ignore(); } /*! \reimp */ -void Q3ScrollView::mouseReleaseEvent(QMouseEvent *e) +void KtlQ3ScrollView::mouseReleaseEvent(QMouseEvent *e) { e->ignore(); } /*! \reimp */ -void Q3ScrollView::mouseDoubleClickEvent(QMouseEvent *e) +void KtlQ3ScrollView::mouseDoubleClickEvent(QMouseEvent *e) { e->ignore(); } /*! \reimp */ -void Q3ScrollView::mouseMoveEvent(QMouseEvent *e) +void KtlQ3ScrollView::mouseMoveEvent(QMouseEvent *e) { e->ignore(); } /*! \reimp */ #ifndef QT_NO_WHEELEVENT -void Q3ScrollView::wheelEvent(QWheelEvent *e) +void KtlQ3ScrollView::wheelEvent(QWheelEvent *e) { /* QWheelEvent ce(viewport()->mapFromGlobal(e->globalPos()), e->globalPos(), e->delta(), e->state()); - 2018.11.30*/ QWheelEvent ce(viewport()->mapFromGlobal(e->globalPos()), e->globalPos(), e->delta(), e->buttons(), e->modifiers()); viewportWheelEvent(&ce); if (!ce.isAccepted()) { - if (e->orientation() == Horizontal && horizontalScrollBar()) + if (e->orientation() == Qt::Horizontal && horizontalScrollBar()) horizontalScrollBar()->event(e); - else if (e->orientation() == Vertical && verticalScrollBar()) + else if (e->orientation() == Qt::Vertical && verticalScrollBar()) verticalScrollBar()->event(e); } else { e->accept(); } } #endif /*! \reimp */ -void Q3ScrollView::contextMenuEvent(QContextMenuEvent *e) +void KtlQ3ScrollView::contextMenuEvent(QContextMenuEvent *e) { if (e->reason() != QContextMenuEvent::Keyboard) { e->ignore(); return; } /* QContextMenuEvent ce(e->reason(), viewport()->mapFromGlobal(e->globalPos()), e->globalPos(), e->state()); - 2018.11.30 */ QContextMenuEvent ce(e->reason(), viewport()->mapFromGlobal(e->globalPos()), e->globalPos(), e->modifiers()); viewportContextMenuEvent(&ce); if (ce.isAccepted()) e->accept(); else e->ignore(); } -Q3ScrollView::ScrollBarMode Q3ScrollView::vScrollBarMode() const +KtlQ3ScrollView::ScrollBarMode KtlQ3ScrollView::vScrollBarMode() const { return d->vMode; } /*! - \enum Q3ScrollView::ScrollBarMode + \enum KtlQ3ScrollView::ScrollBarMode - This enum type describes the various modes of Q3ScrollView's scroll + This enum type describes the various modes of KtlQ3ScrollView's scroll bars. - \value Auto Q3ScrollView shows a scroll bar when the content is + \value Auto KtlQ3ScrollView shows a scroll bar when the content is too large to fit and not otherwise. This is the default. - \value AlwaysOff Q3ScrollView never shows a scroll bar. + \value AlwaysOff KtlQ3ScrollView never shows a scroll bar. - \value AlwaysOn Q3ScrollView always shows a scroll bar. + \value AlwaysOn KtlQ3ScrollView always shows a scroll bar. (The modes for the horizontal and vertical scroll bars are independent.) */ /*! - \property Q3ScrollView::vScrollBarMode + \property KtlQ3ScrollView::vScrollBarMode \brief the mode for the vertical scroll bar - The default mode is Q3ScrollView::Auto. + The default mode is KtlQ3ScrollView::Auto. \sa hScrollBarMode */ -void Q3ScrollView::setVScrollBarMode(ScrollBarMode mode) +void KtlQ3ScrollView::setVScrollBarMode(ScrollBarMode mode) { if (d->vMode != mode) { d->vMode = mode; updateScrollBars(); } } /*! - \property Q3ScrollView::hScrollBarMode + \property KtlQ3ScrollView::hScrollBarMode \brief the mode for the horizontal scroll bar - The default mode is Q3ScrollView::Auto. + The default mode is KtlQ3ScrollView::Auto. \sa vScrollBarMode */ -Q3ScrollView::ScrollBarMode Q3ScrollView::hScrollBarMode() const +KtlQ3ScrollView::ScrollBarMode KtlQ3ScrollView::hScrollBarMode() const { return d->hMode; } -void Q3ScrollView::setHScrollBarMode(ScrollBarMode mode) +void KtlQ3ScrollView::setHScrollBarMode(ScrollBarMode mode) { if (d->hMode != mode) { d->hMode = mode; updateScrollBars(); } } /*! Returns the widget in the corner between the two scroll bars. By default, no corner widget is present. */ -QWidget* Q3ScrollView::cornerWidget() const +QWidget* KtlQ3ScrollView::cornerWidget() const { return d->corner; } /*! Sets the widget in the \a corner between the two scroll bars. You will probably also want to set at least one of the scroll bar modes to \c AlwaysOn. Passing 0 shows no widget in the corner. Any previous \a corner widget is hidden. You may call setCornerWidget() with the same widget at different times. - All widgets set here will be deleted by the Q3ScrollView when it is + All widgets set here will be deleted by the KtlQ3ScrollView when it is destroyed unless you separately reparent the widget after setting some other corner widget (or 0). Any \e newly set widget should have no current parent. By default, no corner widget is present. \sa setVScrollBarMode(), setHScrollBarMode() */ -void Q3ScrollView::setCornerWidget(QWidget* corner) +void KtlQ3ScrollView::setCornerWidget(QWidget* corner) { QWidget* oldcorner = d->corner; if (oldcorner != corner) { if (oldcorner) oldcorner->hide(); d->corner = corner; if (corner) corner->setParent(this); updateScrollBars(); if (corner) corner->show(); } } -void Q3ScrollView::setResizePolicy(ResizePolicy r) +void KtlQ3ScrollView::setResizePolicy(ResizePolicy r) { d->policy = r; } /*! - \property Q3ScrollView::resizePolicy + \property KtlQ3ScrollView::resizePolicy \brief the resize policy The default is \c Default. \sa ResizePolicy */ -Q3ScrollView::ResizePolicy Q3ScrollView::resizePolicy() const +KtlQ3ScrollView::ResizePolicy KtlQ3ScrollView::resizePolicy() const { return d->policy; } /*! \internal */ -void Q3ScrollView::setEnabled(bool enable) +void KtlQ3ScrollView::setEnabled(bool enable) { - Q3Frame::setEnabled(enable); + KtlQ3Frame::setEnabled(enable); } /*! Removes the \a child widget from the scrolled area. Note that this happens automatically if the \a child is deleted. */ -void Q3ScrollView::removeChild(QWidget* child) +void KtlQ3ScrollView::removeChild(QWidget* child) { if (!d || !child) // First check in case we are destructing return; QSVChildRec *r = d->rec(child); if (r) d->deleteChildRec(r); } /*! \internal */ -void Q3ScrollView::removeChild(QObject* child) +void KtlQ3ScrollView::removeChild(QObject* child) { - // Q3Frame::removeChild(child); // 2018.11.30 + // KtlQ3Frame::removeChild(child); // 2018.11.30 if (child) { child->setParent(0); } } /*! Inserts the widget, \a child, into the scrolled area positioned at (\a x, \a y). The position defaults to (0, 0). If the child is already in the view, it is just moved. You may want to call enableClipper(true) if you add a large number of widgets. */ -void Q3ScrollView::addChild(QWidget* child, int x, int y) +void KtlQ3ScrollView::addChild(QWidget* child, int x, int y) { if (!child) { #if defined(QT_CHECK_NULL) - qWarning("Q3ScrollView::addChild(): Cannot add null child"); + qWarning("KtlQ3ScrollView::addChild(): Cannot add null child"); #endif return; } child->ensurePolished(); //child->setBackgroundOrigin(WidgetOrigin); // 2018.11.30 - does nothing in qt4 if (child->parentWidget() == viewport()) { // May already be there QSVChildRec *r = d->rec(child); if (r) { r->moveTo(this,x,y,d->clipped_viewport); if (d->policy > Manual) { d->autoResizeHint(this); d->autoResize(this); // #### better to just deal with this one widget! } return; } } if (d->children.isEmpty() && d->policy != Manual) { if (d->policy == Default) setResizePolicy(AutoOne); child->installEventFilter(this); } else if (d->policy == AutoOne) { child->removeEventFilter(this); //#### ????? setResizePolicy(Manual); } if (child->parentWidget() != viewport()) { //child->reparent(viewport(), 0, QPoint(0,0), false); // 2018.11.30 child->setParent(viewport()); child->setGeometry(0, 0, child->width(), child->height()); } d->addChildRec(child,x,y)->hideOrShow(this, d->clipped_viewport); if (d->policy > Manual) { d->autoResizeHint(this); d->autoResize(this); // #### better to just deal with this one widget! } } /*! Repositions the \a child widget to (\a x, \a y). This function is the same as addChild(). */ -void Q3ScrollView::moveChild(QWidget* child, int x, int y) +void KtlQ3ScrollView::moveChild(QWidget* child, int x, int y) { addChild(child,x,y); } /*! Returns the X position of the given \a child widget. Use this rather than QWidget::x() for widgets added to the view. This function returns 0 if \a child has not been added to the view. */ -int Q3ScrollView::childX(QWidget* child) +int KtlQ3ScrollView::childX(QWidget* child) { QSVChildRec *r = d->rec(child); return r ? r->x : 0; } /*! Returns the Y position of the given \a child widget. Use this rather than QWidget::y() for widgets added to the view. This function returns 0 if \a child has not been added to the view. */ -int Q3ScrollView::childY(QWidget* child) +int KtlQ3ScrollView::childY(QWidget* child) { QSVChildRec *r = d->rec(child); return r ? r->y : 0; } -/*! \fn bool Q3ScrollView::childIsVisible(QWidget*) +/*! \fn bool KtlQ3ScrollView::childIsVisible(QWidget*) \obsolete Returns true if \a child is visible. This is equivalent to child->isVisible(). */ -/*! \fn void Q3ScrollView::showChild(QWidget* child, bool y) +/*! \fn void KtlQ3ScrollView::showChild(QWidget* child, bool y) \obsolete Sets the visibility of \a child. Equivalent to QWidget::show() or QWidget::hide(). */ /*! This event filter ensures the scroll bars are updated when a single contents widget is resized, shown, hidden or destroyed; it - passes mouse events to the Q3ScrollView. The event is in \a e and + passes mouse events to the KtlQ3ScrollView. The event is in \a e and the object is in \a obj. */ -bool Q3ScrollView::eventFilter(QObject *obj, QEvent *e) +bool KtlQ3ScrollView::eventFilter(QObject *obj, QEvent *e) { bool disabled = !(qobject_cast(obj)->isEnabled()); if (!d) return false; // we are destructing if (obj == d->viewport || obj == d->clipped_viewport) { switch (e->type()) { /* Forward many events to viewport...() functions */ case QEvent::Paint: viewportPaintEvent((QPaintEvent*)e); break; case QEvent::Resize: if (!d->clipped_viewport) viewportResizeEvent((QResizeEvent *)e); break; case QEvent::MouseButtonPress: if (disabled) return false; viewportMousePressEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break; case QEvent::MouseButtonRelease: if (disabled) return false; viewportMouseReleaseEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break; case QEvent::MouseButtonDblClick: if (disabled) return false; viewportMouseDoubleClickEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break; case QEvent::MouseMove: if (disabled) return false; viewportMouseMoveEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break; #ifndef QT_NO_DRAGANDDROP case QEvent::DragEnter: if (disabled) return false; viewportDragEnterEvent((QDragEnterEvent*)e); break; case QEvent::DragMove: { if (disabled) return false; if (d->drag_autoscroll) { QPoint vp = ((QDragMoveEvent*) e)->pos(); QRect inside_margin(autoscroll_margin, autoscroll_margin, visibleWidth() - autoscroll_margin * 2, visibleHeight() - autoscroll_margin * 2); if (!inside_margin.contains(vp)) { startDragAutoScroll(); // Keep sending move events ((QDragMoveEvent*)e)->accept(QRect(0,0,0,0)); } } viewportDragMoveEvent((QDragMoveEvent*)e); } break; case QEvent::DragLeave: if (disabled) return false; stopDragAutoScroll(); viewportDragLeaveEvent((QDragLeaveEvent*)e); break; case QEvent::Drop: if (disabled) return false; stopDragAutoScroll(); viewportDropEvent((QDropEvent*)e); break; #endif // QT_NO_DRAGANDDROP #ifndef QT_NO_WHEELEVENT case QEvent::Wheel: if (disabled) return false; break; #endif case QEvent::ContextMenu: if (disabled) return false; viewportContextMenuEvent((QContextMenuEvent*)e); if (((QContextMenuEvent*)e)->isAccepted()) return true; break; case QEvent::ChildRemoved: removeChild((QWidget*)((QChildEvent*)e)->child()); break; case QEvent::LayoutHint: d->autoResizeHint(this); break; default: break; } } else if (d && d->rec((QWidget*)obj)) { // must be a child if (e->type() == QEvent::Resize) d->autoResize(this); else if (e->type() == QEvent::Move) d->autoMove(this); } - return Q3Frame::eventFilter(obj, e); // always continue with standard event processing + return KtlQ3Frame::eventFilter(obj, e); // always continue with standard event processing } /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a mousePressEvent(): the press position in \a e is translated to be a point on the contents. */ -void Q3ScrollView::contentsMousePressEvent(QMouseEvent* e) +void KtlQ3ScrollView::contentsMousePressEvent(QMouseEvent* e) { e->ignore(); } /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a mouseReleaseEvent(): the release position in \a e is translated to be a point on the contents. */ -void Q3ScrollView::contentsMouseReleaseEvent(QMouseEvent* e) +void KtlQ3ScrollView::contentsMouseReleaseEvent(QMouseEvent* e) { e->ignore(); } /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a mouseDoubleClickEvent(): the click position in \a e is translated to be a point on the contents. The default implementation generates a normal mouse press event. */ -void Q3ScrollView::contentsMouseDoubleClickEvent(QMouseEvent* e) +void KtlQ3ScrollView::contentsMouseDoubleClickEvent(QMouseEvent* e) { contentsMousePressEvent(e); // try mouse press event } /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a mouseMoveEvent(): the mouse position in \a e is translated to be a point on the contents. */ -void Q3ScrollView::contentsMouseMoveEvent(QMouseEvent* e) +void KtlQ3ScrollView::contentsMouseMoveEvent(QMouseEvent* e) { e->ignore(); } #ifndef QT_NO_DRAGANDDROP /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a dragEnterEvent(): the drag position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored. */ -void Q3ScrollView::contentsDragEnterEvent(QDragEnterEvent * /* event */) +void KtlQ3ScrollView::contentsDragEnterEvent(QDragEnterEvent * /* event */) { } /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a dragMoveEvent(): the drag position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored. */ -void Q3ScrollView::contentsDragMoveEvent(QDragMoveEvent * /* event */) +void KtlQ3ScrollView::contentsDragMoveEvent(QDragMoveEvent * /* event */) { } /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a dragLeaveEvent(): the drag position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored. */ -void Q3ScrollView::contentsDragLeaveEvent(QDragLeaveEvent * /* event */) +void KtlQ3ScrollView::contentsDragLeaveEvent(QDragLeaveEvent * /* event */) { } /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a dropEvent(): the drop position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored. */ -void Q3ScrollView::contentsDropEvent(QDropEvent * /* event */) +void KtlQ3ScrollView::contentsDropEvent(QDropEvent * /* event */) { } #endif // QT_NO_DRAGANDDROP /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a wheelEvent() in \a{e}: the mouse position is translated to be a point on the contents. */ #ifndef QT_NO_WHEELEVENT -void Q3ScrollView::contentsWheelEvent(QWheelEvent * e) +void KtlQ3ScrollView::contentsWheelEvent(QWheelEvent * e) { e->ignore(); } #endif /*! - This event handler is called whenever the Q3ScrollView receives a + This event handler is called whenever the KtlQ3ScrollView receives a contextMenuEvent() in \a{e}: the mouse position is translated to be a point on the contents. */ -void Q3ScrollView::contentsContextMenuEvent(QContextMenuEvent *e) +void KtlQ3ScrollView::contentsContextMenuEvent(QContextMenuEvent *e) { e->ignore(); } /*! This is a low-level painting routine that draws the viewport contents. Reimplement this if drawContents() is too high-level (for example, if you don't want to open a QPainter on the viewport). The paint event is passed in \a pe. */ -void Q3ScrollView::viewportPaintEvent(QPaintEvent* pe) +void KtlQ3ScrollView::viewportPaintEvent(QPaintEvent* pe) { QWidget* vp = viewport(); QPainter p(vp); QRect r = pe->rect(); if (d->clipped_viewport) { QRect rr( -d->clipped_viewport->x(), -d->clipped_viewport->y(), d->viewport->width(), d->viewport->height() ); r &= rr; if (r.isValid()) { int ex = r.x() + d->clipped_viewport->x() + d->contentsX(); int ey = r.y() + d->clipped_viewport->y() + d->contentsY(); int ew = r.width(); int eh = r.height(); drawContentsOffset(&p, d->contentsX()+d->clipped_viewport->x(), d->contentsY()+d->clipped_viewport->y(), ex, ey, ew, eh); } } else { r &= d->viewport->rect(); int ex = r.x() + d->contentsX(); int ey = r.y() + d->contentsY(); int ew = r.width(); int eh = r.height(); drawContentsOffset(&p, d->contentsX(), d->contentsY(), ex, ey, ew, eh); } } /*! To provide simple processing of events on the contents, this function receives all resize events sent to the viewport. The default implementation does nothing. The \a event parameter is ignored. \sa QWidget::resizeEvent() */ -void Q3ScrollView::viewportResizeEvent(QResizeEvent * /* event */) +void KtlQ3ScrollView::viewportResizeEvent(QResizeEvent * /* event */) { } /*! \internal To provide simple processing of events on the contents, this function receives all mouse press events sent to the viewport, translates the event and calls contentsMousePressEvent(). \sa contentsMousePressEvent(), QWidget::mousePressEvent() */ -void Q3ScrollView::viewportMousePressEvent(QMouseEvent* e) +void KtlQ3ScrollView::viewportMousePressEvent(QMouseEvent* e) { /* QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); - 2018.11.30 */ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->buttons(), e->modifiers()); contentsMousePressEvent(&ce); if (!ce.isAccepted()) e->ignore(); } /*!\internal To provide simple processing of events on the contents, this function receives all mouse release events sent to the viewport, translates the event and calls contentsMouseReleaseEvent(). \sa QWidget::mouseReleaseEvent() */ -void Q3ScrollView::viewportMouseReleaseEvent(QMouseEvent* e) +void KtlQ3ScrollView::viewportMouseReleaseEvent(QMouseEvent* e) { /* QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); -- 2018.11.30 */ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->buttons(), e->modifiers()); contentsMouseReleaseEvent(&ce); if (!ce.isAccepted()) e->ignore(); } /*!\internal To provide simple processing of events on the contents, this function receives all mouse double click events sent to the viewport, translates the event and calls contentsMouseDoubleClickEvent(). \sa QWidget::mouseDoubleClickEvent() */ -void Q3ScrollView::viewportMouseDoubleClickEvent(QMouseEvent* e) +void KtlQ3ScrollView::viewportMouseDoubleClickEvent(QMouseEvent* e) { /* QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); - 2018.11.30 */ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->buttons(), e->modifiers()); contentsMouseDoubleClickEvent(&ce); if (!ce.isAccepted()) e->ignore(); } /*!\internal To provide simple processing of events on the contents, this function receives all mouse move events sent to the viewport, translates the event and calls contentsMouseMoveEvent(). \sa QWidget::mouseMoveEvent() */ -void Q3ScrollView::viewportMouseMoveEvent(QMouseEvent* e) +void KtlQ3ScrollView::viewportMouseMoveEvent(QMouseEvent* e) { QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->buttons(), e->modifiers()); contentsMouseMoveEvent(&ce); if (!ce.isAccepted()) e->ignore(); } #ifndef QT_NO_DRAGANDDROP /*!\internal To provide simple processing of events on the contents, this function receives all drag enter events sent to the viewport, translates the event and calls contentsDragEnterEvent(). \sa QWidget::dragEnterEvent() */ -void Q3ScrollView::viewportDragEnterEvent(QDragEnterEvent* e) +void KtlQ3ScrollView::viewportDragEnterEvent(QDragEnterEvent* e) { //e->setPoint(viewportToContents(e->pos())); // 2018.11.30 QDragEnterEvent ev(viewportToContents(e->pos()), e->possibleActions(), e->mimeData(), e->mouseButtons(), e->keyboardModifiers()); contentsDragEnterEvent(&ev); //e->setPoint(contentsToViewport(e->pos())); // 2018.11.30 } /*!\internal To provide simple processing of events on the contents, this function receives all drag move events sent to the viewport, translates the event and calls contentsDragMoveEvent(). \sa QWidget::dragMoveEvent() */ -void Q3ScrollView::viewportDragMoveEvent(QDragMoveEvent* e) +void KtlQ3ScrollView::viewportDragMoveEvent(QDragMoveEvent* e) { //e->setPoint(viewportToContents(e->pos())); // 2018.11.30 QDragMoveEvent ev(viewportToContents(e->pos()), e->possibleActions(), e->mimeData(), e->mouseButtons(), e->keyboardModifiers()); contentsDragMoveEvent(&ev); //e->setPoint(contentsToViewport(e->pos())); // 2018.11.30 } /*!\internal To provide simple processing of events on the contents, this function receives all drag leave events sent to the viewport and calls contentsDragLeaveEvent(). \sa QWidget::dragLeaveEvent() */ -void Q3ScrollView::viewportDragLeaveEvent(QDragLeaveEvent* e) +void KtlQ3ScrollView::viewportDragLeaveEvent(QDragLeaveEvent* e) { contentsDragLeaveEvent(e); } /*!\internal To provide simple processing of events on the contents, this function receives all drop events sent to the viewport, translates the event and calls contentsDropEvent(). \sa QWidget::dropEvent() */ -void Q3ScrollView::viewportDropEvent(QDropEvent* e) +void KtlQ3ScrollView::viewportDropEvent(QDropEvent* e) { //e->setPoint(viewportToContents(e->pos())); // 2018.11.30 QDropEvent ev(viewportToContents(e->pos()), e->possibleActions(), e->mimeData(), e->mouseButtons(), e->keyboardModifiers()); contentsDropEvent(&ev); //e->setPoint(contentsToViewport(e->pos())); // 2018.11.30 } #endif // QT_NO_DRAGANDDROP /*!\internal To provide simple processing of events on the contents, this function receives all wheel events sent to the viewport, translates the event and calls contentsWheelEvent(). \sa QWidget::wheelEvent() */ #ifndef QT_NO_WHEELEVENT -void Q3ScrollView::viewportWheelEvent(QWheelEvent* e) +void KtlQ3ScrollView::viewportWheelEvent(QWheelEvent* e) { /* Different than standard mouse events, because wheel events might be sent to the focus widget if the widget-under-mouse doesn't want the event itself. */ /* QWheelEvent ce(viewportToContents(e->pos()), e->globalPos(), e->delta(), e->state()); */ QWheelEvent ce(viewportToContents(e->pos()), e->globalPos(), e->delta(), e->buttons(), e->modifiers()); contentsWheelEvent(&ce); if (ce.isAccepted()) e->accept(); else e->ignore(); } #endif /*! \internal To provide simple processing of events on the contents, this function receives all context menu events sent to the viewport, translates the event and calls contentsContextMenuEvent(). */ -void Q3ScrollView::viewportContextMenuEvent(QContextMenuEvent *e) +void KtlQ3ScrollView::viewportContextMenuEvent(QContextMenuEvent *e) { //QContextMenuEvent ce(e->reason(), viewportToContents(e->pos()), e->globalPos(), e->state()); QContextMenuEvent ce(e->reason(), viewportToContents(e->pos()), e->globalPos(), e->modifiers()); contentsContextMenuEvent(&ce); if (ce.isAccepted()) e->accept(); else e->ignore(); } /*! Returns the component horizontal scroll bar. It is made available to allow accelerators, autoscrolling, etc. It should not be used for other purposes. This function never returns 0. */ -QScrollBar* Q3ScrollView::horizontalScrollBar() const +QScrollBar* KtlQ3ScrollView::horizontalScrollBar() const { return d->hbar; } /*! Returns the component vertical scroll bar. It is made available to allow accelerators, autoscrolling, etc. It should not be used for other purposes. This function never returns 0. */ -QScrollBar* Q3ScrollView::verticalScrollBar() const { +QScrollBar* KtlQ3ScrollView::verticalScrollBar() const { return d->vbar; } /*! Scrolls the content so that the point (\a x, \a y) is visible with at least 50-pixel margins (if possible, otherwise centered). */ -void Q3ScrollView::ensureVisible(int x, int y) +void KtlQ3ScrollView::ensureVisible(int x, int y) { ensureVisible(x, y, 50, 50); } /*! \overload Scrolls the content so that the point (\a x, \a y) is visible with at least the \a xmargin and \a ymargin margins (if possible, otherwise centered). */ -void Q3ScrollView::ensureVisible(int x, int y, int xmargin, int ymargin) +void KtlQ3ScrollView::ensureVisible(int x, int y, int xmargin, int ymargin) { int pw=visibleWidth(); int ph=visibleHeight(); int cx=-d->contentsX(); int cy=-d->contentsY(); int cw=d->contentsWidth(); int ch=contentsHeight(); if (pw < xmargin*2) xmargin=pw/2; if (ph < ymargin*2) ymargin=ph/2; if (cw <= pw) { xmargin=0; cx=0; } if (ch <= ph) { ymargin=0; cy=0; } if (x < -cx+xmargin) cx = -x+xmargin; else if (x >= -cx+pw-xmargin) cx = -x+pw-xmargin; if (y < -cy+ymargin) cy = -y+ymargin; else if (y >= -cy+ph-ymargin) cy = -y+ph-ymargin; if (cx > 0) cx=0; else if (cx < pw-cw && cw>pw) cx=pw-cw; if (cy > 0) cy=0; else if (cy < ph-ch && ch>ph) cy=ph-ch; setContentsPos(-cx, -cy); } /*! Scrolls the content so that the point (\a x, \a y) is in the top-left corner. */ -void Q3ScrollView::setContentsPos(int x, int y) +void KtlQ3ScrollView::setContentsPos(int x, int y) { #if 0 // bounds checking... if (QApplication::reverseLayout()) if (x > d->contentsWidth() - visibleWidth()) x = d->contentsWidth() - visibleWidth(); else #endif if (x < 0) x = 0; if (y < 0) y = 0; // Choke signal handling while we update BOTH sliders. d->signal_choke=true; moveContents(-x, -y); d->vbar->setValue(y); d->hbar->setValue(x); d->signal_choke=false; } /*! Scrolls the content by \a dx to the left and \a dy upwards. */ -void Q3ScrollView::scrollBy(int dx, int dy) +void KtlQ3ScrollView::scrollBy(int dx, int dy) { setContentsPos(QMAX(d->contentsX()+dx, 0), QMAX(d->contentsY()+dy, 0)); } /*! Scrolls the content so that the point (\a x, \a y) is in the center of visible area. */ -void Q3ScrollView::center(int x, int y) +void KtlQ3ScrollView::center(int x, int y) { ensureVisible(x, y, 32000, 32000); } /*! \overload Scrolls the content so that the point (\a x, \a y) is visible with the \a xmargin and \a ymargin margins (as fractions of visible the area). For example: \list \i Margin 0.0 allows (x, y) to be on the edge of the visible area. \i Margin 0.5 ensures that (x, y) is in middle 50% of the visible area. \i Margin 1.0 ensures that (x, y) is in the center of the visible area. \endlist */ -void Q3ScrollView::center(int x, int y, float xmargin, float ymargin) +void KtlQ3ScrollView::center(int x, int y, float xmargin, float ymargin) { int pw=visibleWidth(); int ph=visibleHeight(); ensureVisible(x, y, int(xmargin/2.0*pw+0.5), int(ymargin/2.0*ph+0.5)); } /*! - \fn void Q3ScrollView::contentsMoving(int x, int y) + \fn void KtlQ3ScrollView::contentsMoving(int x, int y) This signal is emitted just before the contents are moved to position (\a x, \a y). \sa contentsX(), contentsY() */ /*! Moves the contents by (\a x, \a y). */ -void Q3ScrollView::moveContents(int x, int y) +void KtlQ3ScrollView::moveContents(int x, int y) { if (-x+visibleWidth() > d->contentsWidth()) #if 0 if(QApplication::reverseLayout()) x=QMAX(0,-d->contentsWidth()+visibleWidth()); else #endif x=QMIN(0,-d->contentsWidth()+visibleWidth()); if (-y+visibleHeight() > contentsHeight()) y=QMIN(0,-contentsHeight()+visibleHeight()); int dx = x - d->vx; int dy = y - d->vy; if (!dx && !dy) return; // Nothing to do emit contentsMoving(-x, -y); d->vx = x; d->vy = y; if (d->clipped_viewport || d->static_bg) { // Cheap move (usually) d->moveAllBy(dx,dy); } else if (/*dx && dy ||*/ (QABS(dy) * 5 > visibleHeight() * 4) || (QABS(dx) * 5 > visibleWidth() * 4) ) { // Big move if (viewport()->updatesEnabled()) viewport()->update(); d->moveAllBy(dx,dy); } else if (!d->fake_scroll || d->contentsWidth() > visibleWidth()) { // Small move clipper()->scroll(dx,dy); } d->hideOrShowAll(this, true); } /*! - \property Q3ScrollView::contentsX + \property KtlQ3ScrollView::contentsX \brief the X coordinate of the contents that are at the left edge of the viewport. */ -int Q3ScrollView::contentsX() const +int KtlQ3ScrollView::contentsX() const { return d->contentsX(); } /*! - \property Q3ScrollView::contentsY + \property KtlQ3ScrollView::contentsY \brief the Y coordinate of the contents that are at the top edge of the viewport. */ -int Q3ScrollView::contentsY() const +int KtlQ3ScrollView::contentsY() const { return d->contentsY(); } /*! - \property Q3ScrollView::contentsWidth + \property KtlQ3ScrollView::contentsWidth \brief the width of the contents area */ -int Q3ScrollView::contentsWidth() const +int KtlQ3ScrollView::contentsWidth() const { return d->contentsWidth(); } /*! - \property Q3ScrollView::contentsHeight + \property KtlQ3ScrollView::contentsHeight \brief the height of the contents area */ -int Q3ScrollView::contentsHeight() const +int KtlQ3ScrollView::contentsHeight() const { return d->vheight; } /*! Sets the size of the contents area to \a w pixels wide and \a h pixels high and updates the viewport accordingly. */ -void Q3ScrollView::resizeContents(int w, int h) +void KtlQ3ScrollView::resizeContents(int w, int h) { int ow = d->vwidth; int oh = d->vheight; d->vwidth = w; d->vheight = h; d->scrollbar_timer.setSingleShot(true); d->scrollbar_timer.start(0 /*, true */ ); if (d->children.isEmpty() && d->policy == Default) setResizePolicy(Manual); if (ow > w) { // Swap int t=w; w=ow; ow=t; } // Refresh area ow..w if (ow < visibleWidth() && w >= 0) { if (ow < 0) ow = 0; if (w > visibleWidth()) w = visibleWidth(); clipper()->update(d->contentsX()+ow, 0, w-ow, visibleHeight()); } if (oh > h) { // Swap int t=h; h=oh; oh=t; } // Refresh area oh..h if (oh < visibleHeight() && h >= 0) { if (oh < 0) oh = 0; if (h > visibleHeight()) h = visibleHeight(); clipper()->update(0, d->contentsY()+oh, visibleWidth(), h-oh); } } /*! Calls update() on a rectangle defined by \a x, \a y, \a w, \a h, translated appropriately. If the rectangle is not visible, nothing is repainted. \sa repaintContents() */ -void Q3ScrollView::updateContents(int x, int y, int w, int h) +void KtlQ3ScrollView::updateContents(int x, int y, int w, int h) { if (!isVisible() || !updatesEnabled()) return; QWidget* vp = viewport(); // Translate x -= d->contentsX(); y -= d->contentsY(); if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (w < 0 || h < 0) return; if (x > visibleWidth() || y > visibleHeight()) return; if (w > visibleWidth()) w = visibleWidth(); if (h > visibleHeight()) h = visibleHeight(); if (d->clipped_viewport) { // Translate clipper() to viewport() x -= d->clipped_viewport->x(); y -= d->clipped_viewport->y(); } vp->update(x, y, w, h); } /*! \overload Updates the contents in rectangle \a r */ -void Q3ScrollView::updateContents(const QRect& r) +void KtlQ3ScrollView::updateContents(const QRect& r) { updateContents(r.x(), r.y(), r.width(), r.height()); } /*! \overload */ -void Q3ScrollView::updateContents() +void KtlQ3ScrollView::updateContents() { updateContents(d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight()); } /*! \overload Repaints the contents of rectangle \a r. If \a erase is true the background is cleared using the background color. */ -void Q3ScrollView::repaintContents(const QRect& r, bool erase) +void KtlQ3ScrollView::repaintContents(const QRect& r, bool erase) { repaintContents(r.x(), r.y(), r.width(), r.height(), erase); } /*! \overload Repaints the contents. If \a erase is true the background is cleared using the background color. */ -void Q3ScrollView::repaintContents(bool erase) +void KtlQ3ScrollView::repaintContents(bool erase) { repaintContents(d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight(), erase); } /*! Calls repaint() on a rectangle defined by \a x, \a y, \a w, \a h, translated appropriately. If the rectangle is not visible, nothing is repainted. If \a erase is true the background is cleared using the background color. \sa updateContents() */ -void Q3ScrollView::repaintContents(int x, int y, int w, int h, bool /*erase*/) +void KtlQ3ScrollView::repaintContents(int x, int y, int w, int h, bool /*erase*/) { if (!isVisible() || !updatesEnabled()) return; QWidget* vp = viewport(); // Translate logical to clipper() x -= d->contentsX(); y -= d->contentsY(); if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (w < 0 || h < 0) return; if (w > visibleWidth()) w = visibleWidth(); if (h > visibleHeight()) h = visibleHeight(); if (d->clipped_viewport) { // Translate clipper() to viewport() x -= d->clipped_viewport->x(); y -= d->clipped_viewport->y(); } vp->update(x, y, w, h); } /*! For backward-compatibility only. It is easier to use drawContents(QPainter*,int,int,int,int). The default implementation translates the painter appropriately and calls drawContents(QPainter*,int,int,int,int). See drawContents() for an explanation of the parameters \a p, \a offsetx, \a offsety, \a clipx, \a clipy, \a clipw and \a cliph. */ -void Q3ScrollView::drawContentsOffset(QPainter* p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph) +void KtlQ3ScrollView::drawContentsOffset(QPainter* p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph) { p->translate(-offsetx,-offsety); drawContents(p, clipx, clipy, clipw, cliph); } /*! - \fn void Q3ScrollView::drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph) + \fn void KtlQ3ScrollView::drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph) Reimplement this function if you are viewing a drawing area rather than a widget. The function should draw the rectangle (\a clipx, \a clipy, \a clipw, \a cliph) of the contents using painter \a p. The clip rectangle is in the scrollview's coordinates. For example: \snippet doc/src/snippets/code/src_qt3support_widgets_q3scrollview.cpp 4 The clip rectangle and translation of the painter \a p is already set appropriately. */ -void Q3ScrollView::drawContents(QPainter*, int, int, int, int) +void KtlQ3ScrollView::drawContents(QPainter*, int, int, int, int) { } /*! \reimp */ -void Q3ScrollView::frameChanged() +void KtlQ3ScrollView::frameChanged() { // // slight ugle-hack - the listview header needs readjusting when // // changing the frame // if (Q3ListView *lv = qobject_cast(this)) // lv->triggerUpdate(); - Q3Frame::frameChanged(); + KtlQ3Frame::frameChanged(); updateScrollBars(); } /*! Returns the viewport widget of the scrollview. This is the widget containing the contents widget or which is the drawing area. */ -QWidget* Q3ScrollView::viewport() const +QWidget* KtlQ3ScrollView::viewport() const { if (d->clipped_viewport) return d->clipped_viewport; return d->viewport; } /*! Returns the clipper widget. Contents in the scrollview are ultimately clipped to be inside the clipper widget. You should not need to use this function. \sa visibleWidth(), visibleHeight() */ -QWidget* Q3ScrollView::clipper() const +QWidget* KtlQ3ScrollView::clipper() const { return d->viewport; } /*! - \property Q3ScrollView::visibleWidth + \property KtlQ3ScrollView::visibleWidth \brief the horizontal amount of the content that is visible */ -int Q3ScrollView::visibleWidth() const +int KtlQ3ScrollView::visibleWidth() const { return clipper()->width(); } /*! - \property Q3ScrollView::visibleHeight + \property KtlQ3ScrollView::visibleHeight \brief the vertical amount of the content that is visible */ -int Q3ScrollView::visibleHeight() const +int KtlQ3ScrollView::visibleHeight() const { return clipper()->height(); } -void Q3ScrollView::changeFrameRect(const QRect& r) +void KtlQ3ScrollView::changeFrameRect(const QRect& r) { QRect oldr = frameRect(); if (oldr != r) { QRect cr = contentsRect(); QRegion fr(frameRect()); fr = fr.subtracted(contentsRect()); setFrameRect(r); if (isVisible()) { cr = cr.intersected(contentsRect()); fr = fr.united(frameRect()); fr = fr.subtracted(cr); if (!fr.isEmpty()) update(fr); } } } /*! Sets the margins around the scrolling area to \a left, \a top, \a right and \a bottom. This is useful for applications such as spreadsheets with "locked" rows and columns. The marginal space is \e inside the frameRect() and is left blank; reimplement drawFrame() or put widgets in the unused area. By default all margins are zero. \sa frameChanged() */ -void Q3ScrollView::setMargins(int left, int top, int right, int bottom) +void KtlQ3ScrollView::setMargins(int left, int top, int right, int bottom) { if (left == d->l_marg && top == d->t_marg && right == d->r_marg && bottom == d->b_marg) return; d->l_marg = left; d->t_marg = top; d->r_marg = right; d->b_marg = bottom; updateScrollBars(); } /*! Returns the left margin. \sa setMargins() */ -int Q3ScrollView::leftMargin() const +int KtlQ3ScrollView::leftMargin() const { return d->l_marg; } /*! Returns the top margin. \sa setMargins() */ -int Q3ScrollView::topMargin() const +int KtlQ3ScrollView::topMargin() const { return d->t_marg; } /*! Returns the right margin. \sa setMargins() */ -int Q3ScrollView::rightMargin() const +int KtlQ3ScrollView::rightMargin() const { return d->r_marg; } /*! Returns the bottom margin. \sa setMargins() */ -int Q3ScrollView::bottomMargin() const +int KtlQ3ScrollView::bottomMargin() const { return d->b_marg; } /*! \reimp */ -bool Q3ScrollView::focusNextPrevChild(bool next) +bool KtlQ3ScrollView::focusNextPrevChild(bool next) { // Makes sure that the new focus widget is on-screen, if // necessary by scrolling the scroll view. - bool retval = Q3Frame::focusNextPrevChild(next); + bool retval = KtlQ3Frame::focusNextPrevChild(next); if (retval) { QWidget *w = window()->focusWidget(); if (isAncestorOf(w)) { QSVChildRec *r = d->ancestorRec(w); if (r && (r->child == w || w->isVisibleTo(r->child))) { QPoint cp = r->child->mapToGlobal(QPoint(0, 0)); QPoint cr = w->mapToGlobal(QPoint(0, 0)) - cp; ensureVisible(r->x + cr.x() + w->width()/2, r->y + cr.y() + w->height()/2, w->width()/2, w->height()/2); } } } return retval; } /*! When a large numbers of child widgets are in a scrollview, especially if they are close together, the scrolling performance can suffer greatly. If \a y is true the scrollview will use an extra widget to group child widgets. Note that you may only call enableClipper() prior to adding widgets. */ -void Q3ScrollView::enableClipper(bool y) // note: this method as of 2018.11.30 is unused +void KtlQ3ScrollView::enableClipper(bool y) // note: this method as of 2018.11.30 is unused { if (!d->clipped_viewport == !y) return; if (d->children.count()) - qFatal("May only call Q3ScrollView::enableClipper() before adding widgets"); + qFatal("May only call KtlQ3ScrollView::enableClipper() before adding widgets"); if (y) { - d->clipped_viewport = new QClipperWidget(clipper(), "qt_clipped_viewport", QFlag(d->flags)); + d->clipped_viewport = new KtlQClipperWidget(clipper(), "qt_clipped_viewport", QFlag(d->flags)); d->clipped_viewport->setGeometry(-coord_limit/2,-coord_limit/2, coord_limit,coord_limit); //d->clipped_viewport->setBackgroundMode(d->viewport->backgroundMode()); d->clipped_viewport->setBackgroundRole(d->viewport->backgroundRole()); //d->viewport->setBackgroundMode(NoBackground); // no exposures for this // 2018.11.30 d->viewport->setAttribute(Qt::WA_NoSystemBackground); // hope this is the correct replacement for above d->viewport->removeEventFilter(this); d->clipped_viewport->installEventFilter(this); d->clipped_viewport->show(); } else { delete d->clipped_viewport; d->clipped_viewport = 0; } } /*! Sets the scrollview to have a static background if \a y is true, or a scrolling background if \a y is false. By default, the background is scrolling. Be aware that this mode is quite slow, as a full repaint of the visible area has to be triggered on every contents move. \sa hasStaticBackground() */ -void Q3ScrollView::setStaticBackground(bool y) +void KtlQ3ScrollView::setStaticBackground(bool y) { d->static_bg = y; } /*! - Returns true if Q3ScrollView uses a static background; otherwise + Returns true if KtlQ3ScrollView uses a static background; otherwise returns false. \sa setStaticBackground() */ -bool Q3ScrollView::hasStaticBackground() const +bool KtlQ3ScrollView::hasStaticBackground() const { return d->static_bg; } /*! \overload Returns the point \a p translated to a point on the viewport() widget. */ -QPoint Q3ScrollView::contentsToViewport(const QPoint& p) const +QPoint KtlQ3ScrollView::contentsToViewport(const QPoint& p) const { if (d->clipped_viewport) { return QPoint(p.x() - d->contentsX() - d->clipped_viewport->x(), p.y() - d->contentsY() - d->clipped_viewport->y()); } else { return QPoint(p.x() - d->contentsX(), p.y() - d->contentsY()); } } /*! \overload Returns the point on the viewport \a vp translated to a point in the contents. */ -QPoint Q3ScrollView::viewportToContents(const QPoint& vp) const +QPoint KtlQ3ScrollView::viewportToContents(const QPoint& vp) const { if (d->clipped_viewport) { return QPoint(vp.x() + d->contentsX() + d->clipped_viewport->x(), vp.y() + d->contentsY() + d->clipped_viewport->y()); } else { return QPoint(vp.x() + d->contentsX(), vp.y() + d->contentsY()); } } /*! Translates a point (\a x, \a y) in the contents to a point (\a vx, \a vy) on the viewport() widget. */ -void Q3ScrollView::contentsToViewport(int x, int y, int& vx, int& vy) const +void KtlQ3ScrollView::contentsToViewport(int x, int y, int& vx, int& vy) const { const QPoint v = contentsToViewport(QPoint(x,y)); vx = v.x(); vy = v.y(); } /*! Translates a point (\a vx, \a vy) on the viewport() widget to a point (\a x, \a y) in the contents. */ -void Q3ScrollView::viewportToContents(int vx, int vy, int& x, int& y) const +void KtlQ3ScrollView::viewportToContents(int vx, int vy, int& x, int& y) const { const QPoint c = viewportToContents(QPoint(vx,vy)); x = c.x(); y = c.y(); } /*! \reimp */ -QSize Q3ScrollView::sizeHint() const +QSize KtlQ3ScrollView::sizeHint() const { if (d->use_cached_size_hint && d->cachedSizeHint.isValid()) return d->cachedSizeHint; //constPolish(); // 2018.11.30 ensurePolished(); int f = 2 * frameWidth(); int h = fontMetrics().height(); QSize sz(f, f); if (d->policy > Manual) { QSVChildRec *r = d->children.first(); if (r) { QSize cs = r->child->sizeHint(); if (cs.isValid()) sz += cs.boundedTo(r->child->maximumSize()); else sz += r->child->size(); } } else { sz += QSize(d->contentsWidth(), contentsHeight()); } if (d->vMode == AlwaysOn) sz.setWidth(sz.width() + d->vbar->sizeHint().width()); if (d->hMode == AlwaysOn) sz.setHeight(sz.height() + d->hbar->sizeHint().height()); return sz.expandedTo(QSize(12 * h, 8 * h)) .boundedTo(QSize(36 * h, 24 * h)); } /*! \reimp */ -QSize Q3ScrollView::minimumSizeHint() const +QSize KtlQ3ScrollView::minimumSizeHint() const { int h = fontMetrics().height(); if (h < 10) h = 10; int f = 2 * frameWidth(); return QSize((6 * h) + f, (4 * h) + f); } /*! \reimp (Implemented to get rid of a compiler warning.) */ -void Q3ScrollView::drawContents(QPainter *) +void KtlQ3ScrollView::drawContents(QPainter *) { } #ifndef QT_NO_DRAGANDDROP /*! \internal */ -void Q3ScrollView::startDragAutoScroll() +void KtlQ3ScrollView::startDragAutoScroll() { if (!d->autoscroll_timer.isActive()) { d->autoscroll_time = initialScrollTime; d->autoscroll_accel = initialScrollAccel; d->autoscroll_timer.start(d->autoscroll_time); } } /*! \internal */ -void Q3ScrollView::stopDragAutoScroll() +void KtlQ3ScrollView::stopDragAutoScroll() { d->autoscroll_timer.stop(); } /*! \internal */ -void Q3ScrollView::doDragAutoScroll() +void KtlQ3ScrollView::doDragAutoScroll() { QPoint p = d->viewport->mapFromGlobal(QCursor::pos()); if (d->autoscroll_accel-- <= 0 && d->autoscroll_time) { d->autoscroll_accel = initialScrollAccel; d->autoscroll_time--; d->autoscroll_timer.start(d->autoscroll_time); } int l = QMAX(1, (initialScrollTime- d->autoscroll_time)); int dx = 0, dy = 0; if (p.y() < autoscroll_margin) { dy = -l; } else if (p.y() > visibleHeight() - autoscroll_margin) { dy = +l; } if (p.x() < autoscroll_margin) { dx = -l; } else if (p.x() > visibleWidth() - autoscroll_margin) { dx = +l; } if (dx || dy) { scrollBy(dx,dy); } else { stopDragAutoScroll(); } } /*! - \property Q3ScrollView::dragAutoScroll + \property KtlQ3ScrollView::dragAutoScroll \brief whether autoscrolling in drag move events is enabled - If this property is set to true (the default), the Q3ScrollView + If this property is set to true (the default), the KtlQ3ScrollView automatically scrolls the contents in drag move events if the user moves the cursor close to a border of the view. Of course this works only if the viewport accepts drops. Specifying false disables this autoscroll feature. */ -void Q3ScrollView::setDragAutoScroll(bool b) +void KtlQ3ScrollView::setDragAutoScroll(bool b) { d->drag_autoscroll = b; } -bool Q3ScrollView::dragAutoScroll() const +bool KtlQ3ScrollView::dragAutoScroll() const { return d->drag_autoscroll; } #endif // QT_NO_DRAGANDDROP /*!\internal */ -void Q3ScrollView::setCachedSizeHint(const QSize &sh) const +void KtlQ3ScrollView::setCachedSizeHint(const QSize &sh) const { if (isVisible() && !d->cachedSizeHint.isValid()) d->cachedSizeHint = sh; } /*!\internal */ -void Q3ScrollView::disableSizeHintCaching() +void KtlQ3ScrollView::disableSizeHintCaching() { d->use_cached_size_hint = false; } /*!\internal */ -QSize Q3ScrollView::cachedSizeHint() const +QSize KtlQ3ScrollView::cachedSizeHint() const { return d->use_cached_size_hint ? d->cachedSizeHint : QSize(); } -QT_END_NAMESPACE +// QT_END_NAMESPACE -#endif // QT_NO_SCROLLVIEW +// #include "ktlq3scrollview.moc" diff --git a/src/ktlqt3support/q3scrollview.h b/src/ktlqt3support/ktlq3scrollview.h similarity index 90% rename from src/ktlqt3support/q3scrollview.h rename to src/ktlqt3support/ktlq3scrollview.h index 2e8b859c..22d322a7 100644 --- a/src/ktlqt3support/q3scrollview.h +++ b/src/ktlqt3support/ktlq3scrollview.h @@ -1,253 +1,280 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt3Support module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ -#ifndef Q3SCROLLVIEW_H -#define Q3SCROLLVIEW_H +#ifndef KTL_Q3SCROLLVIEW_H +#define KTL_Q3SCROLLVIEW_H -#include +#include #include -QT_BEGIN_HEADER +// QT_BEGIN_HEADER //QT_BEGIN_NAMESPACE //QT_MODULE(Qt3SupportLight) -class Q3ScrollViewData; +class KtlQ3ScrollViewData; -class Q_COMPAT_EXPORT Q3ScrollView : public Q3Frame +class KtlQ3ScrollView : public KtlQ3Frame { Q_OBJECT Q_ENUMS( ResizePolicy ScrollBarMode ) Q_PROPERTY( ResizePolicy resizePolicy READ resizePolicy WRITE setResizePolicy ) Q_PROPERTY( ScrollBarMode vScrollBarMode READ vScrollBarMode WRITE setVScrollBarMode ) Q_PROPERTY( ScrollBarMode hScrollBarMode READ hScrollBarMode WRITE setHScrollBarMode ) Q_PROPERTY( int visibleWidth READ visibleWidth ) Q_PROPERTY( int visibleHeight READ visibleHeight ) Q_PROPERTY( int contentsWidth READ contentsWidth ) Q_PROPERTY( int contentsHeight READ contentsHeight ) Q_PROPERTY( int contentsX READ contentsX ) Q_PROPERTY( int contentsY READ contentsY ) Q_PROPERTY( bool dragAutoScroll READ dragAutoScroll WRITE setDragAutoScroll ) public: - Q3ScrollView(QWidget* parent=0, const char* name=0, Qt::WindowFlags f=0); - ~Q3ScrollView(); + KtlQ3ScrollView(QWidget* parent=0, const char* name=0, Qt::WindowFlags f=0); + ~KtlQ3ScrollView(); enum ResizePolicy { Default, Manual, AutoOne, AutoOneFit }; virtual void setResizePolicy( ResizePolicy ); ResizePolicy resizePolicy() const; void styleChange( QStyle & ); void removeChild(QWidget* child); virtual void addChild( QWidget* child, int x=0, int y=0 ); virtual void moveChild( QWidget* child, int x, int y ); int childX(QWidget* child); int childY(QWidget* child); bool childIsVisible(QWidget* child) { return child->isVisible(); } // obsolete functions void showChild(QWidget* child, bool yes=true) { child->setVisible(yes); } enum ScrollBarMode { Auto, AlwaysOff, AlwaysOn }; ScrollBarMode vScrollBarMode() const; virtual void setVScrollBarMode( ScrollBarMode ); ScrollBarMode hScrollBarMode() const; virtual void setHScrollBarMode( ScrollBarMode ); QWidget* cornerWidget() const; virtual void setCornerWidget(QWidget*); // ### 4.0: Consider providing a factory function for scrollbars // (e.g. make the two following functions virtual) QScrollBar* horizontalScrollBar() const; QScrollBar* verticalScrollBar() const; QWidget* viewport() const; QWidget* clipper() const; int visibleWidth() const; int visibleHeight() const; int contentsWidth() const; int contentsHeight() const; int contentsX() const; int contentsY() const; void resize( int w, int h ); void resize( const QSize& ); void setVisible(bool visible); void updateContents( int x, int y, int w, int h ); void updateContents( const QRect& r ); void updateContents(); void repaintContents( int x, int y, int w, int h, bool erase=true ); void repaintContents( const QRect& r, bool erase=true ); void repaintContents( bool erase=true ); void contentsToViewport( int x, int y, int& vx, int& vy ) const; void viewportToContents( int vx, int vy, int& x, int& y ) const; QPoint contentsToViewport( const QPoint& ) const; QPoint viewportToContents( const QPoint& ) const; void enableClipper( bool y ); void setStaticBackground( bool y ); bool hasStaticBackground() const; QSize viewportSize( int, int ) const; QSize sizeHint() const; QSize minimumSizeHint() const; void removeChild(QObject* child); bool isHorizontalSliderPressed(); bool isVerticalSliderPressed(); virtual void setDragAutoScroll( bool b ); bool dragAutoScroll() const; Q_SIGNALS: void contentsMoving(int x, int y); void horizontalSliderPressed(); void horizontalSliderReleased(); void verticalSliderPressed(); void verticalSliderReleased(); public Q_SLOTS: virtual void resizeContents( int w, int h ); void scrollBy( int dx, int dy ); virtual void setContentsPos( int x, int y ); void ensureVisible(int x, int y); void ensureVisible(int x, int y, int xmargin, int ymargin); void center(int x, int y); void center(int x, int y, float xmargin, float ymargin); void updateScrollBars(); // ### virtual in 4.0 void setEnabled( bool enable ); protected: virtual void drawContents(QPainter*, int cx, int cy, int cw, int ch); virtual void drawContentsOffset(QPainter*, int ox, int oy, int cx, int cy, int cw, int ch); virtual void contentsMousePressEvent( QMouseEvent* ); virtual void contentsMouseReleaseEvent( QMouseEvent* ); virtual void contentsMouseDoubleClickEvent( QMouseEvent* ); virtual void contentsMouseMoveEvent( QMouseEvent* ); virtual void contentsDragEnterEvent( QDragEnterEvent * ); virtual void contentsDragMoveEvent( QDragMoveEvent * ); virtual void contentsDragLeaveEvent( QDragLeaveEvent * ); virtual void contentsDropEvent( QDropEvent * ); virtual void contentsWheelEvent( QWheelEvent * ); virtual void contentsContextMenuEvent( QContextMenuEvent * ); virtual void viewportPaintEvent( QPaintEvent* ); virtual void viewportResizeEvent( QResizeEvent* ); virtual void viewportMousePressEvent( QMouseEvent* ); virtual void viewportMouseReleaseEvent( QMouseEvent* ); virtual void viewportMouseDoubleClickEvent( QMouseEvent* ); virtual void viewportMouseMoveEvent( QMouseEvent* ); virtual void viewportDragEnterEvent( QDragEnterEvent * ); virtual void viewportDragMoveEvent( QDragMoveEvent * ); virtual void viewportDragLeaveEvent( QDragLeaveEvent * ); virtual void viewportDropEvent( QDropEvent * ); virtual void viewportWheelEvent( QWheelEvent * ); virtual void viewportContextMenuEvent( QContextMenuEvent * ); void frameChanged(); public: virtual void setMargins(int left, int top, int right, int bottom); int leftMargin() const; int topMargin() const; int rightMargin() const; int bottomMargin() const; protected: bool focusNextPrevChild( bool next ); virtual void setHBarGeometry(QScrollBar& hbar, int x, int y, int w, int h); virtual void setVBarGeometry(QScrollBar& vbar, int x, int y, int w, int h); void resizeEvent(QResizeEvent*); void mousePressEvent( QMouseEvent * ); void mouseReleaseEvent( QMouseEvent * ); void mouseDoubleClickEvent( QMouseEvent * ); void mouseMoveEvent( QMouseEvent * ); void wheelEvent( QWheelEvent * ); void contextMenuEvent( QContextMenuEvent * ); bool eventFilter( QObject *, QEvent *e ); void setCachedSizeHint( const QSize &sh ) const; QSize cachedSizeHint() const; void fontChange( const QFont & ); private: void drawContents( QPainter* ); void moveContents(int x, int y); - Q3ScrollViewData* d; + KtlQ3ScrollViewData* d; private Q_SLOTS: void hslide(int); void vslide(int); void hbarIsPressed(); void hbarIsReleased(); void vbarIsPressed(); void vbarIsReleased(); void doDragAutoScroll(); void startDragAutoScroll(); void stopDragAutoScroll(); private: // Disabled copy constructor and operator= - Q_DISABLE_COPY(Q3ScrollView) + Q_DISABLE_COPY(KtlQ3ScrollView) void changeFrameRect(const QRect&); public: void disableSizeHintCaching(); }; + + +class KtlQAbstractScrollAreaWidget : public QWidget +{ + Q_OBJECT + +public: + KtlQAbstractScrollAreaWidget(KtlQ3ScrollView* parent=0, const char* name=0, Qt::WindowFlags f = 0) + : QWidget(parent, f) + { + setObjectName(name); + setAutoFillBackground(true); + } +}; + +class KtlQClipperWidget : public QWidget +{ + Q_OBJECT + +public: + KtlQClipperWidget(QWidget * parent=0, const char * name=0, Qt::WindowFlags f=0) + : QWidget (parent,f) { + setObjectName(name); + } +}; + + //QT_END_NAMESPACE -QT_END_HEADER +// QT_END_HEADER -#endif // Q3SCROLLVIEW_H +#endif // KTL_Q3SCROLLVIEW_H