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

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

Show the popup menu at left-bottom of rect, or at right-bottom if not possible (not enought place). If it isn't possible to show it at bottom, it will be shown on top of rect (top-left if possible, if not it will be top-right). If center is true, it will try to horizontaly center the popup with rect, so it will try two positions : bottom center and then top center.

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

      // 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