summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2010-04-28 09:49:37 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2010-04-28 09:49:37 (GMT)
commite393f03cb89c795e4a638f84b002cb16fd1613a7 (patch)
tree1f9272e1dcf9f162682e9c3571ffb0e6aded1618 /src/gui/widgets
parent1f00130097f81bc78aebb3c055f38c066221bc98 (diff)
parent3eded761167af317bab4f4d8c1ac0a12433eb03a (diff)
downloadQt-e393f03cb89c795e4a638f84b002cb16fd1613a7.zip
Qt-e393f03cb89c795e4a638f84b002cb16fd1613a7.tar.gz
Qt-e393f03cb89c795e4a638f84b002cb16fd1613a7.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qabstractbutton.cpp2
-rw-r--r--src/gui/widgets/qabstractscrollarea.cpp3
-rw-r--r--src/gui/widgets/qcombobox.cpp28
-rw-r--r--src/gui/widgets/qlinecontrol.cpp2
-rw-r--r--src/gui/widgets/qlineedit.cpp9
-rw-r--r--src/gui/widgets/qmenu.cpp52
-rw-r--r--src/gui/widgets/qmenu_mac.mm21
-rw-r--r--src/gui/widgets/qmenubar.cpp6
-rw-r--r--src/gui/widgets/qplaintextedit.cpp8
-rw-r--r--src/gui/widgets/qscrollarea.cpp4
-rw-r--r--src/gui/widgets/qtabbar.cpp15
-rw-r--r--src/gui/widgets/qtabbar_p.h2
12 files changed, 89 insertions, 63 deletions
diff --git a/src/gui/widgets/qabstractbutton.cpp b/src/gui/widgets/qabstractbutton.cpp
index 5ceb237..995d659 100644
--- a/src/gui/widgets/qabstractbutton.cpp
+++ b/src/gui/widgets/qabstractbutton.cpp
@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
#define AUTO_REPEAT_DELAY 300
#define AUTO_REPEAT_INTERVAL 100
-extern bool qt_tab_all_widgets;
+Q_GUI_EXPORT extern bool qt_tab_all_widgets;
/*!
\class QAbstractButton
diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp
index 1d496d5..8cffebd 100644
--- a/src/gui/widgets/qabstractscrollarea.cpp
+++ b/src/gui/widgets/qabstractscrollarea.cpp
@@ -394,7 +394,7 @@ void QAbstractScrollAreaPrivate::layoutChildren()
if ((frameStyle != QFrame::NoFrame) &&
q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &opt, q)) {
controlsRect = widgetRect;
- const int extra = q->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing);
+ const int extra = q->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, &opt, q);
const QPoint cornerExtra(needv ? extra : 0, needh ? extra : 0);
QRect frameRect = widgetRect;
frameRect.adjust(0, 0, -cornerOffset.x() - cornerExtra.x(), -cornerOffset.y() - cornerExtra.y());
@@ -983,6 +983,7 @@ bool QAbstractScrollArea::event(QEvent *e)
case QEvent::StyleChange:
case QEvent::LayoutDirectionChange:
case QEvent::ApplicationLayoutDirectionChange:
+ case QEvent::LayoutRequest:
d->layoutChildren();
// fall through
default:
diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp
index b1a27f2..ca58e6d 100644
--- a/src/gui/widgets/qcombobox.cpp
+++ b/src/gui/widgets/qcombobox.cpp
@@ -76,6 +76,10 @@
#ifndef QT_NO_EFFECTS
# include <private/qeffects_p.h>
#endif
+#if defined(Q_WS_S60)
+#include "private/qt_s60_p.h"
+#endif
+
QT_BEGIN_NAMESPACE
QComboBoxPrivate::QComboBoxPrivate()
@@ -2458,11 +2462,16 @@ void QComboBox::showPopup()
// in portait, menu should be positioned above softkeys
listRect.moveBottom(screen.bottom());
} else {
- // landscape, menu should be at the right and horizontally centered
+ TRect staConTopRect = TRect();
+ AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
listRect.setWidth(listRect.height());
+ //by default popup is centered on screen in landscape
listRect.moveCenter(screen.center());
- (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
- listRect.setLeft(screen.left());
+ if (staConTopRect.IsEmpty()) {
+ // landscape without stacon, menu should be at the right
+ (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
+ listRect.setLeft(screen.left());
+ }
}
#endif
} else if (!boundToScreen || listRect.height() <= belowHeight) {
@@ -2690,13 +2699,18 @@ void QComboBox::changeEvent(QEvent *e)
// in portait, menu should be positioned above softkeys
listRect.moveBottom(screen.bottom());
} else {
- // landscape, menu should be at the right and horizontally centered
+ TRect staConTopRect = TRect();
+ AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
listRect.setWidth(listRect.height());
+ //by default popup is centered on screen in landscape
listRect.moveCenter(screen.center());
- (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
- listRect.setLeft(screen.left());
+ if (staConTopRect.IsEmpty()) {
+ // landscape without stacon, menu should be at the right
+ (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
+ listRect.setLeft(screen.left());
+ }
+ d->container->setGeometry(listRect);
}
- d->container->setGeometry(listRect);
}
}
#endif
diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp
index 42df800..d027b91 100644
--- a/src/gui/widgets/qlinecontrol.cpp
+++ b/src/gui/widgets/qlinecontrol.cpp
@@ -1350,6 +1350,7 @@ bool QLineControl::processEvent(QEvent* ev)
#endif
switch(ev->type()){
#ifndef QT_NO_GRAPHICSVIEW
+ case QEvent::GraphicsSceneMouseDoubleClick:
case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMouseRelease:
case QEvent::GraphicsSceneMousePress:{
@@ -1439,6 +1440,7 @@ void QLineControl::processMouseEvent(QMouseEvent* ev)
moveCursor(cursor, mark);
break;
}
+ case QEvent::GraphicsSceneMouseDoubleClick:
case QEvent::MouseButtonDblClick:
if (ev->button() == Qt::LeftButton) {
selectWordAtPos(xToPos(ev->pos().x()));
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp
index 0b8dca9..655fc61 100644
--- a/src/gui/widgets/qlineedit.cpp
+++ b/src/gui/widgets/qlineedit.cpp
@@ -1869,13 +1869,18 @@ void QLineEdit::paintEvent(QPaintEvent *)
}
QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height());
+ int minLB = qMax(0, -fm.minLeftBearing());
+ int minRB = qMax(0, -fm.minRightBearing());
+
if (d->control->text().isEmpty()) {
if (!hasFocus() && !d->placeholderText.isEmpty()) {
QColor col = pal.text().color();
col.setAlpha(128);
QPen oldpen = p.pen();
p.setPen(col);
- p.drawText(lineRect, va, d->placeholderText);
+ lineRect.adjust(minLB, 0, 0, 0);
+ QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width());
+ p.drawText(lineRect, va, elidedText);
p.setPen(oldpen);
return;
}
@@ -1889,8 +1894,6 @@ void QLineEdit::paintEvent(QPaintEvent *)
// the below code handles all scrolling based on the textline (widthUsed,
// minLB, minRB), the line edit rect (lineRect) and the cursor position
// (cix).
- int minLB = qMax(0, -fm.minLeftBearing());
- int minRB = qMax(0, -fm.minRightBearing());
int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB;
if ((minLB + widthUsed) <= lineRect.width()) {
// text fits in lineRect; use hscroll for alignment
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index 9e190b7..907dd14 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -1805,7 +1805,7 @@ QSize QMenu::sizeHint() const
void QMenu::popup(const QPoint &p, QAction *atAction)
{
Q_D(QMenu);
- if (d->scroll) { //reset scroll state from last popup
+ if (d->scroll) { // reset scroll state from last popup
d->scroll->scrollOffset = 0;
d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone;
}
@@ -1834,7 +1834,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
QSize size = sizeHint();
QRect screen;
#ifndef QT_NO_GRAPHICSVIEW
- bool isEmbedded = d->nearestGraphicsProxyWidget(this);
+ bool isEmbedded = !bypassGraphicsProxyWidget(this) && d->nearestGraphicsProxyWidget(this);
if (isEmbedded)
screen = d->popupGeometry(this);
else
@@ -1860,9 +1860,9 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
}
#endif
if (d->ncols > 1) {
- pos.setY(screen.top()+desktopFrame);
+ pos.setY(screen.top() + desktopFrame);
} else if (atAction) {
- for(int i = 0, above_height = 0; i < d->actions.count(); i++) {
+ for (int i = 0, above_height = 0; i < d->actions.count(); i++) {
QAction *action = d->actions.at(i);
if (action == atAction) {
int newY = pos.y() - above_height;
@@ -1877,7 +1877,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
if (d->scroll && d->scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone
&& !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, 0, this)) {
int below_height = above_height + d->scroll->scrollOffset;
- for(int i2 = i; i2 < d->actionRects.count(); i2++)
+ for (int i2 = i; i2 < d->actionRects.count(); i2++)
below_height += d->actionRects.at(i2).height();
size.setHeight(below_height);
}
@@ -1890,28 +1890,28 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
QPoint mouse = QCursor::pos();
d->mousePopupPos = mouse;
- const bool snapToMouse = (QRect(p.x()-3, p.y()-3, 6, 6).contains(mouse));
+ const bool snapToMouse = (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse));
if (adjustToDesktop) {
- //handle popup falling "off screen"
+ // handle popup falling "off screen"
if (isRightToLeft()) {
- if(snapToMouse) //position flowing left from the mouse
- pos.setX(mouse.x()-size.width());
+ if (snapToMouse) // position flowing left from the mouse
+ pos.setX(mouse.x() - size.width());
#ifndef QT_NO_MENUBAR
- //if in a menubar, it should be right-aligned
+ // if in a menubar, it should be right-aligned
if (qobject_cast<QMenuBar*>(d->causedPopup.widget))
pos.rx() -= size.width();
#endif //QT_NO_MENUBAR
- if (pos.x() < screen.left()+desktopFrame)
- pos.setX(qMax(p.x(), screen.left()+desktopFrame));
- if (pos.x()+size.width()-1 > screen.right()-desktopFrame)
- pos.setX(qMax(p.x()-size.width(), screen.right()-desktopFrame-size.width()+1));
+ if (pos.x() < screen.left() + desktopFrame)
+ pos.setX(qMax(p.x(), screen.left() + desktopFrame));
+ if (pos.x() + size.width() - 1 > screen.right() - desktopFrame)
+ pos.setX(qMax(p.x() - size.width(), screen.right() - desktopFrame - size.width() + 1));
} else {
- if (pos.x()+size.width()-1 > screen.right()-desktopFrame)
- pos.setX(screen.right()-desktopFrame-size.width()+1);
- if (pos.x() < screen.left()+desktopFrame)
+ if (pos.x() + size.width() - 1 > screen.right() - desktopFrame)
+ pos.setX(screen.right() - desktopFrame - size.width() + 1);
+ if (pos.x() < screen.left() + desktopFrame)
pos.setX(screen.left() + desktopFrame);
}
if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) {
@@ -1925,14 +1925,14 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
if (pos.y() < screen.top() + desktopFrame)
pos.setY(screen.top() + desktopFrame);
- if (pos.y()+size.height()-1 > screen.bottom() - desktopFrame) {
+ if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) {
if (d->scroll) {
d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown);
int y = qMax(screen.y(),pos.y());
- size.setHeight(screen.bottom()-(desktopFrame*2)-y);
+ size.setHeight(screen.bottom() - (desktopFrame * 2) - y);
} else {
// Too big for screen, bias to see bottom of menu (for some reason)
- pos.setY(screen.bottom()-size.height()+1);
+ pos.setY(screen.bottom() - size.height() + 1);
}
}
}
@@ -1941,19 +1941,19 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll;
int vGuess = QEffects::DownScroll;
if (isRightToLeft()) {
- if ((snapToMouse && (pos.x() + size.width()/2 > mouse.x())) ||
- (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 > d->causedPopup.widget->x()))
+ if ((snapToMouse && (pos.x() + size.width() / 2 > mouse.x())) ||
+ (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 > d->causedPopup.widget->x()))
hGuess = QEffects::RightScroll;
} else {
- if ((snapToMouse && (pos.x() + size.width()/2 < mouse.x())) ||
- (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 < d->causedPopup.widget->x()))
+ if ((snapToMouse && (pos.x() + size.width() / 2 < mouse.x())) ||
+ (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 < d->causedPopup.widget->x()))
hGuess = QEffects::LeftScroll;
}
#ifndef QT_NO_MENUBAR
- if ((snapToMouse && (pos.y() + size.height()/2 < mouse.y())) ||
+ if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) ||
(qobject_cast<QMenuBar*>(d->causedPopup.widget) &&
- pos.y() + size.width()/2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y()))
+ pos.y() + size.width() / 2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y()))
vGuess = QEffects::UpScroll;
#endif
if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) {
diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm
index 6a0eb53..e8400d6 100644
--- a/src/gui/widgets/qmenu_mac.mm
+++ b/src/gui/widgets/qmenu_mac.mm
@@ -665,6 +665,7 @@ void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bo
}
}
#else
+ bool modalWindowOnScreen = qApp->activeModalWidget() != 0;
for (NSMenuItem *item in [menu itemArray]) {
OSMenuRef submenu = [item submenu];
if (submenu != merge) {
@@ -674,10 +675,20 @@ void qt_mac_set_modal_state_helper_recursive(OSMenuRef menu, OSMenuRef merge, bo
// The item should follow what the QAction has.
if ([item tag]) {
QAction *action = reinterpret_cast<QAction *>([item tag]);
- syncNSMenuItemEnabled(item, action->isEnabled());
- } else {
- syncNSMenuItemEnabled(item, YES);
- }
+ syncNSMenuItemEnabled(item, action->isEnabled());
+ } else {
+ syncNSMenuItemEnabled(item, YES);
+ }
+ // We sneak in some extra code here to handle a menu problem:
+ // If there is no window on screen, we cannot set 'nil' as
+ // menu item target, because then cocoa will disable the item
+ // (guess it assumes that there will be no first responder to
+ // catch the trigger anyway?) OTOH, If we have a modal window,
+ // then setting the menu loader as target will make cocoa not
+ // deliver the trigger because the loader is then seen as modally
+ // shaddowed). So either way there are shortcomings. Instead, we
+ // decide the target as late as possible:
+ [item setTarget:modalWindowOnScreen ? nil : getMenuLoader()];
} else {
syncNSMenuItemEnabled(item, NO);
}
@@ -1820,7 +1831,7 @@ void QMenuBarPrivate::macDestroyMenuBar()
menubars()->remove(tlw);
mac_menubar = 0;
- if (qt_mac_current_menubar.qmenubar == q) {
+ if (!qt_mac_current_menubar.qmenubar || qt_mac_current_menubar.qmenubar == q) {
#ifdef QT_MAC_USE_COCOA
QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader();
[loader removeActionsFromAppMenu];
diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp
index a13a2fa..ef37fd1 100644
--- a/src/gui/widgets/qmenubar.cpp
+++ b/src/gui/widgets/qmenubar.cpp
@@ -1931,9 +1931,9 @@ void QMenuBar::setNativeMenuBar(bool nativeMenuBar)
d->macCreateMenuBar(parentWidget());
}
macUpdateMenuBar();
- updateGeometry();
- setVisible(false);
- setVisible(true);
+ updateGeometry();
+ if (!d->nativeMenuBar && parentWidget())
+ setVisible(true);
#endif
}
}
diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp
index ef9fac3..2734fba 100644
--- a/src/gui/widgets/qplaintextedit.cpp
+++ b/src/gui/widgets/qplaintextedit.cpp
@@ -944,8 +944,8 @@ void QPlainTextEditPrivate::_q_adjustScrollbars()
int vSliderLength = 0;
if (!centerOnScroll && q->isVisible()) {
QTextBlock block = doc->lastBlock();
- const int visible = static_cast<int>(viewport->rect().height() - margin - 1);
- int y = 0;
+ const qreal visible = viewport->rect().height() - margin - 1;
+ qreal y = 0;
int visibleFromBottom = 0;
while (block.isValid()) {
@@ -953,7 +953,7 @@ void QPlainTextEditPrivate::_q_adjustScrollbars()
block = block.previous();
continue;
}
- y += int(documentLayout->blockBoundingRect(block).height());
+ y += documentLayout->blockBoundingRect(block).height();
QTextLayout *layout = block.layout();
int layoutLineCount = layout->lineCount();
@@ -962,7 +962,7 @@ void QPlainTextEditPrivate::_q_adjustScrollbars()
while (lineNumber < layoutLineCount) {
QTextLine line = layout->lineAt(lineNumber);
const QRectF lr = line.naturalTextRect();
- if (int(lr.top()) >= y - visible)
+ if (lr.top() >= y - visible)
break;
++lineNumber;
}
diff --git a/src/gui/widgets/qscrollarea.cpp b/src/gui/widgets/qscrollarea.cpp
index 6b81d9f..38e799e 100644
--- a/src/gui/widgets/qscrollarea.cpp
+++ b/src/gui/widgets/qscrollarea.cpp
@@ -482,14 +482,14 @@ void QScrollArea::ensureWidgetVisible(QWidget *childWidget, int xmargin, int yma
d->hbar->setValue(focusRect.center().x() - d->viewport->width() / 2);
else if (focusRect.right() > visibleRect.right())
d->hbar->setValue(focusRect.right() - d->viewport->width());
- else
+ else if (focusRect.left() < visibleRect.left())
d->hbar->setValue(focusRect.left());
if (focusRect.height() > visibleRect.height())
d->vbar->setValue(focusRect.center().y() - d->viewport->height() / 2);
else if (focusRect.bottom() > visibleRect.bottom())
d->vbar->setValue(focusRect.bottom() - d->viewport->height());
- else
+ else if (focusRect.top() < visibleRect.top())
d->vbar->setValue(focusRect.top());
}
diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp
index 7559311..d03a2f4 100644
--- a/src/gui/widgets/qtabbar.cpp
+++ b/src/gui/widgets/qtabbar.cpp
@@ -580,16 +580,10 @@ void QTabBarPrivate::layoutTab(int index)
}
}
-void QTabBarPrivate::layoutWidgets(int index)
+void QTabBarPrivate::layoutWidgets(int start)
{
Q_Q(QTabBar);
- int start = 0;
- int end = q->count();
- if (index != -1) {
- start = qMax(index, 0);
- end = qMin(end, start + 1);
- }
- for (int i = start; i < end; ++i) {
+ for (int i = start; i < q->count(); ++i) {
layoutTab(i);
}
}
@@ -1171,8 +1165,9 @@ void QTabBar::setCurrentIndex(int index)
update();
d->makeVisible(index);
d->tabList[index].lastTab = oldIndex;
- d->layoutWidgets(oldIndex);
- d->layoutWidgets(index);
+ if (oldIndex >= 0 && oldIndex < count())
+ d->layoutTab(oldIndex);
+ d->layoutTab(index);
#ifdef QT3_SUPPORT
emit selected(index);
#endif
diff --git a/src/gui/widgets/qtabbar_p.h b/src/gui/widgets/qtabbar_p.h
index 83636e6..37741f7 100644
--- a/src/gui/widgets/qtabbar_p.h
+++ b/src/gui/widgets/qtabbar_p.h
@@ -178,7 +178,7 @@ public:
void refresh();
void layoutTabs();
- void layoutWidgets(int index = -1);
+ void layoutWidgets(int start = 0);
void layoutTab(int index);
void updateMacBorderMetrics();
void setupMovableTab();