Logo Search packages:      
Sourcecode: basket version File versions  Download package

void PopupMenu::execAtRectRight ( QPopupMenu &  menu,
const QRect &  rect,
bool  centered = false 
)

Idem execAtRectBottom but on the right or left sides, prior aligned with the top of the rect, and at the bottom if not possible. If center is true, it will try to vertically center the popup with rect, so it will try two positions : right center and then left center.

Definition at line 109 of file popupmenu.cpp.

{
      QSize menuSize = menu.sizeHint() - QSize(1, 1); // A size is [1..n] => We want two lengths that are [0..(n-1)]
      int desktopWidth  = kapp->desktop()->width();   //  to be compared/added/substracted with QRects/QPoints...
      int desktopHeight = kapp->desktop()->height();

      /** Paint the rect on the screen (desktop).
        * For test purpose only (to be sure the passed rectangle is right).
        * Comment this (and the qpainter and qpen includes) for a non-debug version.
        */
      /*QPainter paint(kapp->desktop(), kapp->desktop(), true);
      paint.setPen( QPen(Qt::black, 1) );
      paint.drawRect(rect);
      paint.end();*/

      // rect.topRight() and rect.topLeft() must be VISIBLE :
      //  show the menu 1 pixel more RIGHT (add 1 in X) :
      QPoint point = rect.topRight() + QPoint(1, 0);
      if (point.x() + menuSize.width() < desktopWidth) { // First try at right
            if (centered)
                  point = QPoint( point.x(), rect.center().y() - menuSize.height() / 2 );
            else if (point.y() + menuSize.height() < desktopHeight) //   Then, try at top-right
                  /*point is already set*/;
            else                                             //   Overwise, at top-left
                  point = rect.bottomRight() - QPoint(-1, menuSize.height());
      // Idem : rect.topLeft() and rect.bottomLeft() must be VISIBLE :
      //  show the menu 1 pixel more LEFT (substract 1 in X) :
      } else {                                             // Overwize, try at top
            if (centered)
                  point = QPoint( rect.left() - menuSize.width() - 1, rect.center().y() - menuSize.height() / 2 );
            else if (point.y() + menuSize.height() < desktopHeight) //   Then, try at top-left
                  point = rect.topLeft()  - QPoint(menuSize.width() + 1, 0);
            else                                             //   Overwise, at bottom-left
                  point = rect.bottomLeft() - QPoint(menuSize.width() + 1, menuSize.height());
      }

      // No need to clip : it will be done by menu.exec(...)

      // And show the menu :
      menu.exec( point + QPoint(0, MENU_Y_OFFSET) ); // Stupid offset (QT bug ?) : we should show the menus 2 pixels more bottom !
}


Generated by  Doxygen 1.6.0   Back to index