4141namespace ads
4242{
4343// ============================================================================
44- static QPixmap createDropIndicatorPixmap_old (const QPalette& pal, const QSizeF& size, DockWidgetArea DockWidgetArea)
44+ static QPixmap createDropIndicatorPixmap (const QPalette& pal, const QSizeF& size, DockWidgetArea DockWidgetArea,
45+ CDockOverlay::eMode Mode)
4546{
4647 QColor borderColor = pal.color (QPalette::Active, QPalette::Highlight);
4748 QColor backgroundColor = pal.color (QPalette::Active, QPalette::Base);
48- QColor areaBackgroundColor = pal.color (QPalette::Active, QPalette::Highlight).lighter (150 );
4949
5050 QPixmap pm (size.width (), size.height ());
5151 pm.fill (QColor (0 , 0 , 0 , 0 ));
@@ -59,114 +59,44 @@ static QPixmap createDropIndicatorPixmap_old(const QPalette& pal, const QSizeF&
5959
6060 // Fill
6161 p.fillRect (ShadowRect, QColor (0 , 0 , 0 , 64 ));
62- p.fillRect (baseRect, backgroundColor);
6362
6463 // Drop area rect.
6564 p.save ();
6665 QRectF areaRect;
6766 QLineF areaLine;
68- QLinearGradient gradient ;
67+ QRectF nonAreaRect ;
6968 switch (DockWidgetArea)
7069 {
7170 case TopDockWidgetArea:
7271 areaRect = QRectF (baseRect.x (), baseRect.y (), baseRect.width (), baseRect.height () * .5f );
72+ nonAreaRect = QRectF (baseRect.x (), ShadowRect.height () * .5f , baseRect.width (), baseRect.height () * .5f );
7373 areaLine = QLineF (areaRect.bottomLeft (), areaRect.bottomRight ());
74- gradient.setStart (areaRect.topLeft ());
75- gradient.setFinalStop (areaRect.bottomLeft ());
7674 break ;
7775 case RightDockWidgetArea:
7876 areaRect = QRectF (ShadowRect.width () * .5f , baseRect.y (), baseRect.width () * .5f , baseRect.height ());
77+ nonAreaRect = QRectF (baseRect.x (), baseRect.y (), baseRect.width () * .5f , baseRect.height ());
7978 areaLine = QLineF (areaRect.topLeft (), areaRect.bottomLeft ());
80- gradient.setStart (areaRect.topLeft ());
81- gradient.setFinalStop (areaRect.topRight ());
8279 break ;
8380 case BottomDockWidgetArea:
8481 areaRect = QRectF (baseRect.x (), ShadowRect.height () * .5f , baseRect.width (), baseRect.height () * .5f );
82+ nonAreaRect = QRectF (baseRect.x (), baseRect.y (), baseRect.width (), baseRect.height () * .5f );
8583 areaLine = QLineF (areaRect.topLeft (), areaRect.topRight ());
86- gradient.setStart (areaRect.topLeft ());
87- gradient.setFinalStop (areaRect.bottomLeft ());
8884 break ;
8985 case LeftDockWidgetArea:
9086 areaRect = QRectF (baseRect.x (), baseRect.y (), baseRect.width () * .5f , baseRect.height ());
87+ nonAreaRect = QRectF (ShadowRect.width () * .5f , baseRect.y (), baseRect.width () * .5f , baseRect.height ());
9188 areaLine = QLineF (areaRect.topRight (), areaRect.bottomRight ());
92- gradient.setStart (areaRect.topLeft ());
93- gradient.setFinalStop (areaRect.topRight ());
9489 break ;
9590 default :
9691 break ;
9792 }
98- if (areaRect.isValid ())
99- {
100- gradient.setColorAt (0 .f , areaBackgroundColor);
101- gradient.setColorAt (1 .f , areaBackgroundColor.lighter (120 ));
102- p.fillRect (areaRect, gradient);
10393
104- pen = p.pen ();
105- pen.setColor (borderColor);
106- pen.setStyle (Qt::DashLine);
107- p.setPen (pen);
108- p.drawLine (areaLine);
94+ if (CDockOverlay::ModeContainerOverlay == Mode)
95+ {
96+ baseRect = areaRect;
10997 }
110- p.restore ();
111-
112- p.save ();
113- pen = p.pen ();
114- pen.setColor (borderColor);
115- pen.setWidth (1 );
116-
117- p.setPen (pen);
118- p.drawRect (baseRect.adjusted (0 , 0 , -pen.width (), -pen.width ()));
119- p.restore ();
120- return pm;
121- }
122-
12398
124- // ============================================================================
125- static QPixmap createDropIndicatorPixmap (const QPalette& pal, const QSizeF& size, DockWidgetArea DockWidgetArea)
126- {
127- QColor borderColor = pal.color (QPalette::Active, QPalette::Highlight);
128- QColor backgroundColor = pal.color (QPalette::Active, QPalette::Base);
129- // QColor areaBackgroundColor = pal.color(QPalette::Active, QPalette::Highlight).lighter(150);
130-
131- QPixmap pm (size.width (), size.height ());
132- pm.fill (QColor (0 , 0 , 0 , 0 ));
133-
134- QPainter p (&pm);
135- QPen pen = p.pen ();
136- QRectF ShadowRect (pm.rect ());
137- QRectF baseRect;
138- baseRect.setSize (ShadowRect.size () * 0.7 );
139- baseRect.moveCenter (ShadowRect.center ());
140-
141- // Fill
142- p.fillRect (ShadowRect, QColor (0 , 0 , 0 , 64 ));
14399 p.fillRect (baseRect, backgroundColor);
144-
145- // Drop area rect.
146- p.save ();
147- QRectF areaRect;
148- QLineF areaLine;
149- switch (DockWidgetArea)
150- {
151- case TopDockWidgetArea:
152- areaRect = QRectF (baseRect.x (), baseRect.y (), baseRect.width (), baseRect.height () * .5f );
153- areaLine = QLineF (areaRect.bottomLeft (), areaRect.bottomRight ());
154- break ;
155- case RightDockWidgetArea:
156- areaRect = QRectF (ShadowRect.width () * .5f , baseRect.y (), baseRect.width () * .5f , baseRect.height ());
157- areaLine = QLineF (areaRect.topLeft (), areaRect.bottomLeft ());
158- break ;
159- case BottomDockWidgetArea:
160- areaRect = QRectF (baseRect.x (), ShadowRect.height () * .5f , baseRect.width (), baseRect.height () * .5f );
161- areaLine = QLineF (areaRect.topLeft (), areaRect.topRight ());
162- break ;
163- case LeftDockWidgetArea:
164- areaRect = QRectF (baseRect.x (), baseRect.y (), baseRect.width () * .5f , baseRect.height ());
165- areaLine = QLineF (areaRect.topRight (), areaRect.bottomRight ());
166- break ;
167- default :
168- break ;
169- }
170100 if (areaRect.isValid ())
171101 {
172102 pen = p.pen ();
@@ -186,32 +116,72 @@ static QPixmap createDropIndicatorPixmap(const QPalette& pal, const QSizeF& size
186116 p.restore ();
187117
188118 p.save ();
119+ // Draw outer border
189120 pen = p.pen ();
190121 pen.setColor (borderColor);
191122 pen.setWidth (1 );
192-
193123 p.setBrush (Qt::NoBrush);
194124 p.setPen (pen);
195125 p.drawRect (baseRect);
196126
127+ // draw window title bar
197128 p.setBrush (borderColor);
198129 QRectF FrameRect (baseRect.topLeft (), QSizeF (baseRect.width (), baseRect.height () / 10 ));
199130 p.drawRect (FrameRect);
200131 p.restore ();
132+
133+ if (CDockOverlay::ModeContainerOverlay == Mode)
134+ {
135+ QRectF ArrowRect;
136+ ArrowRect.setSize (ShadowRect.size () * 0.7 );
137+ ArrowRect.setWidth (ArrowRect.width () / 4.6 );
138+ ArrowRect.setHeight (ArrowRect.height () / 2 );
139+ ArrowRect.moveCenter (QPointF (0 , 0 ));
140+ QPolygonF Arrow;
141+ Arrow << ArrowRect.topLeft ()
142+ << QPointF ( ArrowRect.right (), ArrowRect.center ().y ())
143+ << ArrowRect.bottomLeft ();
144+ p.setPen (Qt::NoPen);
145+ p.setBrush (backgroundColor);
146+ p.setRenderHint (QPainter::Antialiasing, true );
147+ p.translate (nonAreaRect.center ().x (), nonAreaRect.center ().y ());
148+
149+ switch (DockWidgetArea)
150+ {
151+ case TopDockWidgetArea:
152+ p.rotate (-90 );
153+ break ;
154+ case RightDockWidgetArea:
155+ break ;
156+ case BottomDockWidgetArea:
157+ p.rotate (90 );
158+ break ;
159+ case LeftDockWidgetArea:
160+ p.rotate (180 );
161+ break ;
162+ default :
163+ break ;
164+ }
165+
166+ p.drawPolygon (Arrow);
167+ }
168+
201169 return pm;
202170}
203171
204172
205173// ============================================================================
206- QWidget* createDropIndicatorWidget (DockWidgetArea DockWidgetArea)
174+ QWidget* createDropIndicatorWidget (DockWidgetArea DockWidgetArea,
175+ CDockOverlay::eMode Mode)
207176{
208177 QLabel* l = new QLabel ();
209178 l->setObjectName (" DockWidgetAreaLabel" );
210179
211180 const qreal metric = static_cast <qreal>(l->fontMetrics ().height ()) * 3 .f ;
212181 const QSizeF size (metric, metric);
213182
214- l->setPixmap (createDropIndicatorPixmap (l->palette (), size, DockWidgetArea));
183+ l->setPixmap (createDropIndicatorPixmap (l->palette (), size, DockWidgetArea,
184+ Mode));
215185 l->setWindowFlags (Qt::Tool | Qt::FramelessWindowHint);
216186 l->setAttribute (Qt::WA_TranslucentBackground);
217187 return l;
@@ -230,6 +200,7 @@ struct DockOverlayPrivate
230200 QRect TargetRect;
231201 DockWidgetArea LastLocation = InvalidDockWidgetArea;
232202 bool DropPreviewEnabled = true ;
203+ CDockOverlay::eMode Mode = CDockOverlay::ModeDockAreaOverlay;
233204
234205 /* *
235206 * Private data constructor
@@ -267,6 +238,7 @@ CDockOverlay::CDockOverlay(QWidget* parent, eMode Mode) :
267238 QFrame (parent),
268239 d (new DockOverlayPrivate(this ))
269240{
241+ d->Mode = Mode;
270242 d->Cross = new CDockOverlayCross (this );
271243 setWindowFlags (Qt::Tool | Qt::FramelessWindowHint);
272244 setWindowOpacity (1 );
@@ -359,8 +331,6 @@ DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
359331 resize (target->size ());
360332 QPoint TopLeft = target->mapToGlobal (target->rect ().topLeft ());
361333 move (TopLeft);
362- std::cout << " Overlay top: " << TopLeft.x () << " left: " << TopLeft.y ()
363- << std::endl;
364334 show ();
365335 return dropAreaUnderCursor ();
366336}
@@ -397,12 +367,16 @@ void CDockOverlay::paintEvent(QPaintEvent* event)
397367 QRect r = rect ();
398368 const DockWidgetArea da = dropAreaUnderCursor ();
399369 // std::cout << "CursorLocation: " << dropAreaUnderCursor() << std::endl;
370+
371+ double Factor = (CDockOverlay::ModeContainerOverlay == d->Mode ) ?
372+ 3 : 2 ;
373+
400374 switch (da)
401375 {
402- case TopDockWidgetArea: r.setHeight (r.height () / 2 ); break ;
403- case RightDockWidgetArea: r.setX (r.width () / 2 ); break ;
404- case BottomDockWidgetArea: r.setY (r.height () / 2 ); break ;
405- case LeftDockWidgetArea: r.setWidth (r.width () / 2 ); break ;
376+ case TopDockWidgetArea: r.setHeight (r.height () / Factor ); break ;
377+ case RightDockWidgetArea: r.setX (r.width () * ( 1 - 1 / Factor) ); break ;
378+ case BottomDockWidgetArea: r.setY (r.height () * ( 1 - 1 / Factor) ); break ;
379+ case LeftDockWidgetArea: r.setWidth (r.width () / Factor ); break ;
406380 case CenterDockWidgetArea: r = rect ();break ;
407381 default : return ;
408382 }
@@ -505,11 +479,11 @@ void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode)
505479 d->Mode = Mode;
506480
507481 QHash<DockWidgetArea, QWidget*> areaWidgets;
508- areaWidgets.insert (TopDockWidgetArea, createDropIndicatorWidget (TopDockWidgetArea));
509- areaWidgets.insert (RightDockWidgetArea, createDropIndicatorWidget (RightDockWidgetArea));
510- areaWidgets.insert (BottomDockWidgetArea, createDropIndicatorWidget (BottomDockWidgetArea));
511- areaWidgets.insert (LeftDockWidgetArea, createDropIndicatorWidget (LeftDockWidgetArea));
512- areaWidgets.insert (CenterDockWidgetArea, createDropIndicatorWidget (CenterDockWidgetArea));
482+ areaWidgets.insert (TopDockWidgetArea, createDropIndicatorWidget (TopDockWidgetArea, Mode ));
483+ areaWidgets.insert (RightDockWidgetArea, createDropIndicatorWidget (RightDockWidgetArea, Mode ));
484+ areaWidgets.insert (BottomDockWidgetArea, createDropIndicatorWidget (BottomDockWidgetArea, Mode ));
485+ areaWidgets.insert (LeftDockWidgetArea, createDropIndicatorWidget (LeftDockWidgetArea, Mode ));
486+ areaWidgets.insert (CenterDockWidgetArea, createDropIndicatorWidget (CenterDockWidgetArea, Mode ));
513487
514488 setAreaWidgets (areaWidgets);
515489}
0 commit comments