[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegraphics/kpovmodeler
From: Andreas Zehender <az () azweb ! de>
Date: 2007-03-11 10:29:03
Message-ID: 1173608943.502038.1755.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 641434 by azehende:
show drag rectangle (use overlay widget)
M +81 -107 pmdockwidget.cpp
M +37 -35 pmdockwidget.h
--- trunk/KDE/kdegraphics/kpovmodeler/pmdockwidget.cpp #641433:641434
@@ -487,6 +487,7 @@
,formerDockPos(DockNone)
,pix(new QPixmap(pixmap))
,prevSideDockPosBeforeDrag(DockNone)
+ ,m_dragRectangle(PMDockWidget::DockNone)
{
d = new PMDockWidgetPrivate(); // create private data
@@ -519,6 +520,11 @@
setWindowIcon( pixmap );
widget = 0L;
+ QFrame* frame = new QFrame(this);
+ frame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
+ frame->hide();
+ m_pDragOverlay = frame;
+
QObject::connect(this, SIGNAL(hasUndocked()), manager->main, \
SLOT(slotDockWidgetUndocked()) ); applyToWidget( parent, QPoint(0,0) );
}
@@ -1237,6 +1243,7 @@
if(manager == obj) manager = 0;
}
+/*
void PMDockWidget::drawDragRectangle(const QRect& r){
// TODO use transparent overlay widget
d->drawRectangle = true;
@@ -1261,23 +1268,68 @@
QWidget::paintEvent( ev );
}
}
+*/
+void PMDockWidget::setDragRectangle(PMDockWidget::DockPosition pos){
+ if(m_dragRectangle != pos){
+ m_dragRectangle = pos;
+ if(m_dragRectangle){
+ updateDragOverlay();
+ m_pDragOverlay->raise();
+ m_pDragOverlay->show();
+ } else {
+ m_pDragOverlay->hide();
+ }
+ }
+}
+
+void PMDockWidget::resizeEvent(QResizeEvent *rsize)
+{
+ QWidget::resizeEvent(rsize);
+ updateDragOverlay();
+}
+
+void PMDockWidget::updateDragOverlay(){
+ QRect base = QRect(QPoint(0,0), size());
+ if(widget) base = widget->geometry();
+ QRect rect = base;
+
+ switch(m_dragRectangle){
+ case DockTop:
+ rect.setHeight(base.height()/5-1);
+ m_pDragOverlay->setGeometry(rect);
+ break;
+ case DockBottom:
+ rect.setHeight(base.height()/5-1);
+ rect.moveBottom(base.bottom());
+ m_pDragOverlay->setGeometry(rect);
+ break;
+ case DockLeft:
+ rect.setWidth(base.width()/5-1);
+ m_pDragOverlay->setGeometry(rect);
+ break;
+ case DockRight:
+ rect.setWidth(base.width()/5-1);
+ rect.moveRight(base.right());
+ m_pDragOverlay->setGeometry(rect);
+ break;
+ case DockCenter:
+ rect.setHeight(base.height()/3-1);
+ rect.setWidth(base.width()/3-1);
+ rect.moveCenter(base.center());
+ m_pDragOverlay->setGeometry(rect);
+ break;
+ default:
+ break;
+ }
+}
+
/**************************************************************************************/
class PMDockManager::PMDockManagerPrivate
{
public:
- /**
- * This rectangle is used to highlight the current dockposition. It stores global \
screen coordinates.
- */
- QRect dragRect;
-
- /**
- * This rectangle is used to erase the previously highlighted dockposition. It \
stores global screen coordinates.
- */
- QRect oldDragRect;
-
- /**
+ /**
* This flag stores the information if dragging is ready to start. Used between \
mousePress and mouseMove event.
*/
bool readyToDrag;
@@ -1358,25 +1410,6 @@
bool PMDockManager::eventFilter( QObject *obj, QEvent *event )
{
-/* This doesn't seem to fullfill any sense, other than breaking
- QMainWindow's layout all over the place
- The first child of the mainwindow is not necessarily a meaningful
- content widget but in Qt3's QMainWindow it can easily be a QToolBar.
- In short: QMainWindow knows how to layout its children, no need to
- mess that up.
-
- >>>>>I need this in the PMDockArea at the moment (JoWenn)
-
- if ( obj == main && event->type() == QEvent::Resize && \
dynamic_cast<PMDockArea*>(main) && main->children() ){
-#ifndef NO_KDE2
- kDebug()<<"PMDockManager::eventFilter(): main is a PMDockArea and there are \
children"<<endl;
-#endif
- QWidget* fc = (QWidget*)main->children()->getFirst();
- if ( fc )
- fc->setGeometry( QRect(QPoint(0,0), main->geometry().size()) );
- }
-*/
-
if ( obj->inherits("PMDockWidgetAbstractHeaderDrag") ){
PMDockWidget* pDockWdgAtCursor = 0L;
PMDockWidget* curdw = ((PMDockWidgetAbstractHeaderDrag*)obj)->dockWidget();
@@ -1397,15 +1430,8 @@
childDockWidgetList = new QWidgetList();
childDockWidgetList->append( curdw );
findChildDockWidget( curdw, childDockWidgetList );
-
- d->oldDragRect = QRect();
- d->dragRect = QRect(curdw->geometry());
- QPoint p = curdw->mapToGlobal(QPoint(0,0));
- d->dragRect.moveTopLeft(p);
- drawDragRectangle();
+
d->readyToDrag = true;
- d->button = ((QMouseEvent*)event)->button();
-
d->dragOffset = QCursor::pos()-currentDragWidget->mapToGlobal(QPoint(0,0));
}
}
@@ -1419,12 +1445,9 @@
cancelDrop();
}
if (d->readyToDrag) {
+ if(currentDragWidget) \
currentDragWidget->setDragRectangle(PMDockWidget::DockNone); \
+ if(currentMoveWidget) \
currentMoveWidget->setDragRectangle(PMDockWidget::DockNone); d->readyToDrag = false;
- d->oldDragRect = QRect();
- d->dragRect = QRect(curdw->geometry());
- QPoint p = curdw->mapToGlobal(QPoint(0,0));
- d->dragRect.moveTopLeft(p);
- drawDragRectangle();
currentDragWidget = 0L;
delete childDockWidgetList;
childDockWidgetList = 0L;
@@ -1437,32 +1460,29 @@
if ( draging ) {
pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
PMDockWidget* oldMoveWidget = currentMoveWidget;
- if ( currentMoveWidget && pDockWdgAtCursor == currentMoveWidget ) { //move
+ if ( currentMoveWidget && pDockWdgAtCursor == currentMoveWidget ) { //move
dragMove( currentMoveWidget, currentMoveWidget->mapFromGlobal( QCursor::pos() \
) ); break;
} else {
- if (dropCancel && curdw) {
- d->dragRect = QRect(curdw->geometry());
- QPoint p = curdw->mapToGlobal(QPoint(0,0));
- d->dragRect.moveTopLeft(p);
- }else
- d->dragRect = QRect();
-
- drawDragRectangle();
+ if(currentDragWidget) \
currentDragWidget->setDragRectangle(PMDockWidget::DockNone); \
+ if(currentMoveWidget) \
currentMoveWidget->setDragRectangle(PMDockWidget::DockNone); }
if ( !pDockWdgAtCursor && (curdw->eDocking & (int)PMDockWidget::DockDesktop) == \
0 ){ // just moving at the desktop
+ if(currentMoveWidget) \
currentMoveWidget->setDragRectangle(PMDockWidget::DockNone); currentMoveWidget = \
pDockWdgAtCursor; curPos = PMDockWidget::DockDesktop;
} else {
if ( oldMoveWidget && pDockWdgAtCursor != currentMoveWidget ) { //leave
+ if(currentMoveWidget) \
currentMoveWidget->setDragRectangle(PMDockWidget::DockNone); currentMoveWidget = \
pDockWdgAtCursor; curPos = PMDockWidget::DockDesktop;
}
}
if ( oldMoveWidget != pDockWdgAtCursor && pDockWdgAtCursor ) { //enter \
pDockWdgAtCursor + if(currentMoveWidget) \
currentMoveWidget->setDragRectangle(PMDockWidget::DockNone); currentMoveWidget = \
pDockWdgAtCursor; curPos = PMDockWidget::DockDesktop;
}
@@ -1610,9 +1630,7 @@
QSize r = dw->widget->size();
if ( dw->parentDockTabGroup() ){
curPos = PMDockWidget::DockCenter;
- if ( oldPos != curPos ) {
- d->dragRect.setRect( p.x()+2, p.y()+2, r.width()-4, r.height()-4 );
- }
+ dw->setDragRectangle(PMDockWidget::DockCenter);
return;
}
@@ -1627,39 +1645,24 @@
if ( pos.y() <= h )
{
curPos = PMDockWidget::DockTop;
- w = r.width();
}
else if ( pos.y() >= 2*h )
{
curPos = PMDockWidget::DockBottom;
- p.setY( p.y() + 2*h );
- w = r.width();
}
else if ( pos.x() <= w )
{
curPos = PMDockWidget::DockLeft;
- h = r.height();
- p.setY( cwp.y( ) );
- h = cwh;
}
else if ( pos.x() >= 2*w )
{
curPos = PMDockWidget::DockRight;
- p.setX( p.x() + 2*w );
- p.setY( cwp.y( ) );
- h = cwh;
}
else
{
curPos = PMDockWidget::DockCenter;
- p.setX( p.x() + w );
- p.setY( p.y() + h );
}
-
- if ( oldPos != curPos ) {
- d->dragRect.setRect( p.x(), p.y(), w, h );
- drawDragRectangle();
- }
+ dw->setDragRectangle(curPos);
}
@@ -1670,15 +1673,15 @@
delete childDockWidgetList;
childDockWidgetList = 0L;
- d->dragRect = QRect(); // cancel drawing
- drawDragRectangle(); // only the old rect will be deleted
+ if(currentDragWidget && currentDragWidget->dragRectangle()) \
currentDragWidget->setDragRectangle(PMDockWidget::DockNone); + if(currentMoveWidget \
&& currentMoveWidget->dragRectangle()) \
currentMoveWidget->setDragRectangle(PMDockWidget::DockNone); }
void PMDockManager::drop()
{
- d->dragRect = QRect(); // cancel drawing
- drawDragRectangle(); // only the old rect will be deleted
+ if(currentDragWidget && currentDragWidget->dragRectangle()) \
currentDragWidget->setDragRectangle(PMDockWidget::DockNone); + if(currentMoveWidget \
&& currentMoveWidget->dragRectangle()) \
currentMoveWidget->setDragRectangle(PMDockWidget::DockNone);
QApplication::restoreOverrideCursor();
@@ -1687,8 +1690,11 @@
if ( dropCancel ) return;
if ( !currentMoveWidget && ((currentDragWidget->eDocking & \
(int)PMDockWidget::DockDesktop) == 0) ) { + // TODO is this neede here? we already \
cleared the drag rect + /*
d->dragRect = QRect(); // cancel drawing
drawDragRectangle(); // only the old rect will be deleted
+ */
return;
}
if ( !currentMoveWidget && !currentDragWidget->parent() ) {
@@ -1807,38 +1813,6 @@
return found;
}
-void PMDockManager::drawDragRectangle()
-{
- if (d->oldDragRect == d->dragRect)
- return;
-
- // TODO fixme
- /*
- int i;
- QRect oldAndNewDragRect[2];
- oldAndNewDragRect[0] = d->oldDragRect;
- oldAndNewDragRect[1] = d->dragRect;
-
- // 2 calls, one for the old and one for the new drag rectangle
- for (i = 0; i <= 1; i++) {
- if (oldAndNewDragRect[i].isEmpty())
- continue;
-
- QWidget* w = (PMDockWidget*) QApplication::widgetAt( \
oldAndNewDragRect[i].topLeft() );
- while(w && !w->inherits("PMDockWidget")) w = w->parentWidget();
- if(!w) continue;
-
- QRect r = oldAndNewDragRect[i];
- r.moveTopLeft( r.topLeft() - w->mapToGlobal(QPoint(0,0)) );
- ((PMDockWidget*)w)->drawDragRectangle(r);
- }
- */
-
- // memorize the current rectangle for later removing
- d->oldDragRect = d->dragRect;
-}
-
-
#ifdef _JOWENN_EXPERIMENTAL_
PMDockArea::PMDockArea( QWidget* parent)
--- trunk/KDE/kdegraphics/kpovmodeler/pmdockwidget.h #641433:641434
@@ -600,14 +600,13 @@
*/
DockPosition getDockPosition( ) const { return currentDockPos; }
/**
- * Paints the drag rectangle
+ * Returns the position of the drag rectacle
*/
- void drawDragRectangle(const QRect& r);
-protected:
+ DockPosition dragRectangle() const { return m_dragRectangle; }
/**
- * Draws the drag panel (a double line)
+ * Sets the new drag rectangle position
*/
- virtual void paintEvent( QPaintEvent* );
+ void setDragRectangle(DockPosition pos);
public slots:
/**
@@ -717,6 +716,9 @@
*/
QString tabPageTitle;
+protected:
+ virtual void resizeEvent(QResizeEvent *);
+
private:
/**
* Sets the caption (window title) of the given tab widget.
@@ -733,6 +735,10 @@
* @param p the point to move to (if it doesn't reparent)
*/
void applyToWidget( QWidget* s, const QPoint& p = QPoint(0,0) );
+ /**
+ * Updates position and size of drag overlay
+ */
+ void updateDragOverlay();
/**
* A base class pointer to the header of this dockwidget
@@ -780,6 +786,8 @@
Qt::Orientation splitterOrientation;
bool isGroup;
bool isTabGroup;
+ DockPosition m_dragRectangle;
+ QWidget* m_pDragOverlay;
private:
PMDockWidgetPrivate *d;
@@ -930,12 +938,12 @@
*/
void setDockDefaultPos( PMDockWidget* );
- private slots:
+private slots:
- /**
- * Clears the popupmenu for showing/hiding dockwidgets and fills it with the \
current states of all controlled dockwidgets.
- */
- void slotMenuPopup();
+ /**
+ * Clears the popupmenu for showing/hiding dockwidgets and fills it with the \
current states of all controlled dockwidgets. + */
+ void slotMenuPopup();
/**
* This method assumes a menuitem of the popupmenu for showing/hiding dockwidgets \
is selected and toggles that state. @@ -944,12 +952,6 @@
*/
void slotMenuActivated( int id);
- /* clears the old drawn drag rectangle (oldDragRect) from screen and
- * draws the new current drag rectangle (dragRect) depending on the current mouse \
position.
- * This highlights the dockwidget which is the currently chosen target during a \
dock action.
- */
- void drawDragRectangle();
-
private:
/**
@@ -1280,24 +1282,24 @@
*/
PMDockManager* dockManager;
- protected slots:
- /**
- * Called whenever one of the dockwidgets of this has been undocked.
- */
- void slotDockWidgetUndocked();
-
+protected slots:
+ /**
+ * Called whenever one of the dockwidgets of this has been undocked.
+ */
+ void slotDockWidgetUndocked();
+
// kparts/dockmainwindow stuff
- protected slots:
+protected slots:
- /**
- * Create the GUI (by merging the host's and the active part's)
- *
- * Called on startup and whenever the active part changes
- * For this you need to connect this slot to the
- * @ref KPartManager::activePartChanged() signal
- * @param part The active part (set to 0L if no part).
- */
- void createGUI( KParts::Part * part );
+ /**
+ * Create the GUI (by merging the host's and the active part's)
+ *
+ * Called on startup and whenever the active part changes
+ * For this you need to connect this slot to the
+ * @ref KPartManager::activePartChanged() signal
+ * @param part The active part (set to 0L if no part).
+ */
+ void createGUI( KParts::Part * part );
/**
* Called when the active part wants to change the statusbar message
@@ -1375,10 +1377,10 @@
PMDockWidget* mainDockWidget;
PMDockManager* dockManager;
- protected slots:
- void slotDockWidgetUndocked();
+protected slots:
+ void slotDockWidgetUndocked();
-public:
+protected:
virtual void resizeEvent(QResizeEvent *);
private:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic