20#include "kexiscrollview.h"
23#include <tqobjectlist.h>
28#include <kstaticdeleter.h>
31#include <utils/kexirecordnavigator.h>
33#include <kexiutils/utils.h>
36class KexiScrollViewData
39 TQPixmap horizontalOuterAreaPixmapBuffer;
40 TQPixmap verticalOuterAreaPixmapBuffer;
44static KStaticDeleter<KexiScrollViewData> KexiScrollView_data_deleter;
45KexiScrollViewData* KexiScrollView_data = 0;
48 : TQScrollView(parent,
"kexiscrollview", WStaticContents)
52 , m_scrollViewNavPanel(0)
54 setFrameStyle(TQFrame::WinPanel | TQFrame::Sunken);
55 viewport()->setPaletteBackgroundColor(colorGroup().mid());
56 TQColor fc = palette().active().foreground(),
57 bc = viewport()->paletteBackgroundColor();
61 m_helpFont.setPointSize( m_helpFont.pointSize() * 3 );
63 setFocusPolicy(TQWidget::WheelFocus);
67 setResizePolicy(Manual);
69 viewport()->setMouseTracking(
true);
71 m_enableResizing =
true;
74 m_outerAreaVisible =
true;
79 refreshContentsSizeLater(
true,
true);
83 m_scrollViewNavPanel->setSizePolicy(TQSizePolicy::Minimum,TQSizePolicy::Preferred);
87KexiScrollView::~KexiScrollView()
92KexiScrollView::setWidget(TQWidget *w)
99KexiScrollView::setRecordNavigatorVisible(
bool visible)
102 m_scrollViewNavPanel->hide();
104 m_scrollViewNavPanel->show();
105 updateNavPanelGeometry();
110KexiScrollView::setSnapToGrid(
bool enable,
int gridSize)
112 m_snapToGrid = enable;
114 m_gridSize = gridSize;
119KexiScrollView::refreshContentsSizeLater(
bool horizontal,
bool vertical)
121 Q_UNUSED( horizontal );
122 Q_UNUSED( vertical );
127 m_hsmode = hScrollBarMode();
130 setVScrollBarMode(TQScrollView::AlwaysOff);
132 setHScrollBarMode(TQScrollView::AlwaysOff);
134 m_delayedResize.start( 100,
true );
143 resizeContents(m_widget->width(), m_widget->height());
147 setHScrollBarMode(m_hsmode);
153 int w = contentsWidth(), h = contentsHeight();
155 const int delta_x = TQMAX( (KexiScrollView_data ?
156 KexiScrollView_data->verticalOuterAreaPixmapBuffer.width() : 0), 300);
157 const int delta_y = TQMAX( (KexiScrollView_data ?
158 KexiScrollView_data->horizontalOuterAreaPixmapBuffer.height() : 0), 300);
159 if((m_widget->width() + delta_x * 2 / 3) > w) {
160 w = m_widget->width() + delta_x;
163 else if((w - m_widget->width()) > delta_x) {
164 w = m_widget->width() + delta_x;
167 if((m_widget->height() + delta_y * 2 / 3) > h) {
168 h = m_widget->height() + delta_y;
171 else if((h - m_widget->height()) > delta_y) {
172 h = m_widget->height() + delta_y;
177 viewport()->repaint();
179 updateContents(0, 0, 2000,2000);
180 clipper()->repaint();
182 resizeContents(w, h);
187 setVScrollBarMode(Auto);
188 setHScrollBarMode(Auto);
195KexiScrollView::updateNavPanelGeometry()
197 if (m_scrollViewNavPanel)
198 m_scrollViewNavPanel->updateGeometry(leftMargin());
202KexiScrollView::contentsMousePressEvent(TQMouseEvent *ev)
207 TQRect r3(0, 0, m_widget->width() + 4, m_widget->height() + 4);
208 if(!r3.contains(ev->pos()))
210 emit outerAreaClicked();
212 if(!m_enableResizing)
215 TQRect r(m_widget->width(), 0, 4, m_widget->height() + 4);
216 TQRect r2(0, m_widget->height(), m_widget->width() + 4, 4);
217 if(r.contains(ev->pos()) || r2.contains(ev->pos()))
220 emit resizingStarted();
225KexiScrollView::contentsMouseReleaseEvent(TQMouseEvent *)
229 emit resizingEnded();
236KexiScrollView::contentsMouseMoveEvent(TQMouseEvent *ev)
238 if(!m_widget || !m_enableResizing)
243 int tmpx = ev->x(), tmpy = ev->y();
244 const int exceeds_x = (tmpx - contentsX() + 5) - clipper()->width();
245 const int exceeds_y = (tmpy - contentsY() + 5) - clipper()->height();
250 if ((tmpx - contentsX()) < 0)
252 if ((tmpy - contentsY()) < 0)
256 TQObjectList *list = m_widget->queryList(
"TQWidget", 0,
true,
false );
257 for(TQObject *o = list->first(); o; o = list->next())
259 TQWidget *w = (TQWidget*)o;
260 tmpx = TQMAX(tmpx, (w->geometry().right() + 10));
261 tmpy = TQMAX(tmpy, (w->geometry().bottom() + 10));
266 if(cursor().shape() == TQCursor::SizeHorCursor)
269 neww = int(
float(tmpx) /
float(m_gridSize) + 0.5 ) * m_gridSize;
272 newh = m_widget->height();
274 else if(cursor().shape() == TQCursor::SizeVerCursor)
276 neww = m_widget->width();
278 newh = int(
float(tmpy) /
float(m_gridSize) + 0.5 ) * m_gridSize;
282 else if(cursor().shape() == TQCursor::SizeFDiagCursor)
285 neww = int(
float(tmpx) /
float(m_gridSize) + 0.5 ) * m_gridSize;
286 newh = int(
float(tmpy) /
float(m_gridSize) + 0.5 ) * m_gridSize;
293 if (neww!=-1 && m_widget->size() != TQSize(neww, newh)) {
294 m_widget->resize( neww, newh );
301 TQPoint p = ev->pos();
302 TQRect r(m_widget->width(), 0, 4, m_widget->height());
303 TQRect r2(0, m_widget->height(), m_widget->width(), 4);
304 TQRect r3(m_widget->width(), m_widget->height(), 4, 4);
307 setCursor(TQCursor::SizeHorCursor);
308 else if(r2.contains(p))
309 setCursor(TQCursor::SizeVerCursor);
310 else if(r3.contains(p))
311 setCursor(TQCursor::SizeFDiagCursor);
318KexiScrollView::setupPixmapBuffer(TQPixmap& pixmap,
const TQString& text,
int lines)
322 TQFontMetrics fm(m_helpFont);
323 const int flags = TQt::AlignCenter|TQt::AlignTop;
324 TQRect rect(fm.boundingRect(0,0,1000,1000,flags,text));
325 const int txtw = rect.width(), txth = rect.height();
326 pixmap = TQPixmap(txtw, txth);
327 if (!pixmap.isNull()) {
329 pixmap.fill( viewport()->paletteBackgroundColor() );
330 TQPainter pb(&pixmap,
this);
331 pb.setPen(m_helpColor);
332 pb.setFont(m_helpFont);
333 pb.drawText(0, 0, txtw, txth, TQt::AlignCenter|TQt::AlignTop, text);
338KexiScrollView::drawContents( TQPainter * p,
int clipx,
int clipy,
int clipw,
int cliph )
340 TQScrollView::drawContents(p, clipx, clipy, clipw, cliph);
342 if(m_preview || !m_outerAreaVisible)
346 const int wx = childX(m_widget);
347 const int wy = childY(m_widget);
348 p->setPen(palette().active().foreground());
349 p->drawLine(wx+m_widget->width(), wy, wx+m_widget->width(), wy+m_widget->height());
350 p->drawLine(wx, wy+m_widget->height(), wx+m_widget->width(), wy+m_widget->height());
353 if (!KexiScrollView_data) {
354 KexiScrollView_data_deleter.setObject( KexiScrollView_data,
new KexiScrollViewData() );
357 setupPixmapBuffer( KexiScrollView_data->horizontalOuterAreaPixmapBuffer, i18n(
"Outer Area"), 1 );
358 setupPixmapBuffer( KexiScrollView_data->verticalOuterAreaPixmapBuffer, i18n(
"Outer\nArea"), 2 );
360 if (!KexiScrollView_data->horizontalOuterAreaPixmapBuffer.isNull()
361 && !KexiScrollView_data->verticalOuterAreaPixmapBuffer.isNull()
362 && !m_delayedResize.isActive() )
364 if (m_widget->height()>(KexiScrollView_data->verticalOuterAreaPixmapBuffer.height()+20)) {
366 TQMAX( m_widget->width(), KexiScrollView_data->verticalOuterAreaPixmapBuffer.width() + 20 ) + 20,
367 TQMAX( (m_widget->height() - KexiScrollView_data->verticalOuterAreaPixmapBuffer.height())/2, 20 ),
368 KexiScrollView_data->verticalOuterAreaPixmapBuffer
372 TQMAX( (m_widget->width() - KexiScrollView_data->horizontalOuterAreaPixmapBuffer.width())/2, 20 ),
373 TQMAX( m_widget->height(), KexiScrollView_data->horizontalOuterAreaPixmapBuffer.height() + 20 ) + 20,
374 KexiScrollView_data->horizontalOuterAreaPixmapBuffer
381KexiScrollView::leaveEvent( TQEvent *e )
383 TQWidget::leaveEvent(e);
388KexiScrollView::setHBarGeometry( TQScrollBar & hbar,
int x,
int y,
int w,
int h )
392 if (m_scrollViewNavPanel && m_scrollViewNavPanel->isVisible()) {
396 hbar.setGeometry( x, y, w, h );
401KexiScrollView::recordNavigator()
const
403 return m_scrollViewNavPanel;
406#include "kexiscrollview.moc"
KexiRecordNavigator class provides a record navigator.
void setHBarGeometry(TQScrollBar &hbar, int x, int y, int w, int h)
KEXIUTILS_EXPORT TQColor blendedColors(const TQColor &c1, const TQColor &c2, int factor1=1, int factor2=1)