diff options
Diffstat (limited to 'src/gui')
27 files changed, 452 insertions, 731 deletions
diff --git a/src/gui/dialogs/qdialog.cpp b/src/gui/dialogs/qdialog.cpp index 90a15b0..0f98b56 100644 --- a/src/gui/dialogs/qdialog.cpp +++ b/src/gui/dialogs/qdialog.cpp @@ -901,15 +901,13 @@ bool QDialog::symbianAdjustedPosition() QPoint p; const bool doS60Positioning = !(isFullScreen()||isMaximized()); if (doS60Positioning) { + QPoint oldPos = pos(); // naive way to deduce screen orientation if (S60->screenHeightInPixels > S60->screenWidthInPixels) { int cbaHeight; - const CEikButtonGroupContainer* bgContainer = S60->buttonGroupContainer(); - if (!bgContainer) { - cbaHeight = 0; - } else { - cbaHeight = qt_TSize2QSize(bgContainer->Size()).height(); - } + TRect rect; + AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EControlPane, rect); + cbaHeight = rect.Height(); p.setY(S60->screenHeightInPixels - height() - cbaHeight); p.setX(0); } else { @@ -939,7 +937,8 @@ bool QDialog::symbianAdjustedPosition() p.setX(qMax(0,S60->screenWidthInPixels - width())); } } - move(p); + if (oldPos != p || p.y() < 0) + move(p); } return doS60Positioning; #else diff --git a/src/gui/dialogs/qfiledialog_mac.mm b/src/gui/dialogs/qfiledialog_mac.mm index 6c1d7f6..a233d4f 100644 --- a/src/gui/dialogs/qfiledialog_mac.mm +++ b/src/gui/dialogs/qfiledialog_mac.mm @@ -726,6 +726,14 @@ bool QFileDialogPrivate::setVisible_sys(bool visible) if (!visible == q->isHidden()) return false; + if (q->windowFlags() & Qt::WindowStaysOnTopHint) { + // The native file dialog tries all it can to stay + // on the NSModalPanel level. And it might also show + // its own "create directory" dialog that we cannot control. + // So we need to use the non-native version in this case... + return false; + } + #ifndef QT_MAC_USE_COCOA return visible ? showCarbonNavServicesDialog() : hideCarbonNavServicesDialog(); #else diff --git a/src/gui/dialogs/qinputdialog.cpp b/src/gui/dialogs/qinputdialog.cpp index 9e4b9b6..1724316 100644 --- a/src/gui/dialogs/qinputdialog.cpp +++ b/src/gui/dialogs/qinputdialog.cpp @@ -234,6 +234,8 @@ void QInputDialogPrivate::ensureLayout() //we want to let the input dialog grow to available size on Symbian. #ifndef Q_OS_SYMBIAN mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); +#else + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); #endif mainLayout->addWidget(label); mainLayout->addWidget(inputWidget); diff --git a/src/gui/graphicsview/qgraphicslayoutitem.cpp b/src/gui/graphicsview/qgraphicslayoutitem.cpp index 770f4dd..7bdf035 100644 --- a/src/gui/graphicsview/qgraphicslayoutitem.cpp +++ b/src/gui/graphicsview/qgraphicslayoutitem.cpp @@ -129,7 +129,6 @@ void QGraphicsLayoutItemPrivate::init() { sizeHintCacheDirty = true; sizeHintWithConstraintCacheDirty = true; - sizePolicy = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); } /*! @@ -395,6 +394,7 @@ QGraphicsLayoutItem::QGraphicsLayoutItem(QGraphicsLayoutItem *parent, bool isLay { Q_D(QGraphicsLayoutItem); d->init(); + d->sizePolicy = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); d->q_ptr = this; } @@ -405,6 +405,7 @@ QGraphicsLayoutItem::QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd) : d_ptr(&dd) { Q_D(QGraphicsLayoutItem); + d->init(); d->q_ptr = this; } diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 73f1493..b2fb22a 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -2493,7 +2493,7 @@ QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const QVariant value = d->scene->inputMethodQuery(query); if (value.type() == QVariant::RectF) - value = mapFromScene(value.toRectF()).boundingRect(); + value = d->mapRectFromScene(value.toRectF()); else if (value.type() == QVariant::PointF) value = mapFromScene(value.toPointF()); else if (value.type() == QVariant::Rect) diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 4a1b9b9..d48d63d 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -89,7 +89,7 @@ QCoeFepInputContext::QCoeFepInputContext(QObject *parent) m_fepState->SetFlags(EAknEditorFlagDefault); m_fepState->SetDefaultInputMode( EAknEditorTextInputMode ); m_fepState->SetPermittedInputModes( EAknEditorAllInputModes ); - m_fepState->SetDefaultCase( EAknEditorLowerCase ); + m_fepState->SetDefaultCase( EAknEditorTextCase ); m_fepState->SetPermittedCases( EAknEditorAllCaseModes ); m_fepState->SetSpecialCharacterTableResourceId(R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG); m_fepState->SetNumericKeymap( EAknEditorStandardNumberModeKeymap ); @@ -657,6 +657,8 @@ void QCoeFepInputContext::UpdateFepInlineTextL(const TDesC& aNewInlineText, if (!w) return; + commitTemporaryPreeditString(); + m_inlinePosition = aPositionOfInsertionPointInInlineText; QList<QInputMethodEvent::Attribute> attributes; @@ -694,6 +696,12 @@ void QCoeFepInputContext::SetInlineEditingCursorVisibilityL(TBool aCursorVisibil void QCoeFepInputContext::CancelFepInlineEdit() { + // We are not supposed to ever have a tempPreeditString and a real preedit string + // from S60 at the same time, so it should be safe to rely on this test to determine + // whether we should honor S60's request to clear the text or not. + if (m_hasTempPreeditString) + return; + QList<QInputMethodEvent::Attribute> attributes; QInputMethodEvent event(QLatin1String(""), attributes); event.setCommitString(QLatin1String(""), 0, 0); diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index f7122d6..1bb43fa 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -630,6 +630,8 @@ QAbstractItemView::QAbstractItemView(QAbstractItemViewPrivate &dd, QWidget *pare */ QAbstractItemView::~QAbstractItemView() { + // stop this timer here before ~QObject + d_func()->delayedReset.stop(); } /*! diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index b5409df..de84966 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -1103,6 +1103,9 @@ QApplication::~QApplication() QApplicationPrivate::is_app_closing = true; QApplicationPrivate::is_app_running = false; + delete QWidgetPrivate::mapper; + QWidgetPrivate::mapper = 0; + // delete all widgets if (QWidgetPrivate::allWidgets) { QWidgetSet *mySet = QWidgetPrivate::allWidgets; @@ -1132,9 +1135,6 @@ QApplication::~QApplication() delete d->ignore_cursor; d->ignore_cursor = 0; #endif - delete QWidgetPrivate::mapper; - QWidgetPrivate::mapper = 0; - delete QApplicationPrivate::app_pal; QApplicationPrivate::app_pal = 0; delete QApplicationPrivate::sys_pal; diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 5f01bcb..0c4b307 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -667,9 +667,6 @@ void QSymbianControl::HandleStatusPaneSizeChange() { QS60MainAppUi *s60AppUi = static_cast<QS60MainAppUi *>(S60->appUi()); s60AppUi->HandleStatusPaneSizeChange(); - // Send resize event to trigger desktopwidget workAreaResized signal - QResizeEvent e(qt_desktopWidget->size(), qt_desktopWidget->size()); - QApplication::sendEvent(qt_desktopWidget, &e); } #endif @@ -1177,8 +1174,10 @@ void QSymbianControl::SizeChanged() if (!slowResize && tlwExtra) tlwExtra->inTopLevelResize = false; } else { - QResizeEvent *e = new QResizeEvent(newSize, oldSize); - QApplication::postEvent(qwidget, e); + if (!qwidget->testAttribute(Qt::WA_PendingResizeEvent)) { + QResizeEvent *e = new QResizeEvent(newSize, oldSize); + QApplication::postEvent(qwidget, e); + } } } @@ -1310,6 +1309,9 @@ void QSymbianControl::HandleResourceChange(int resourceType) case KEikDynamicLayoutVariantSwitch: { handleClientAreaChange(); + // Send resize event to trigger desktopwidget workAreaResized signal + QResizeEvent e(qt_desktopWidget->size(), qt_desktopWidget->size()); + QApplication::sendEvent(qt_desktopWidget, &e); break; } #endif @@ -1636,6 +1638,13 @@ void qt_cleanup() //Change mouse pointer back S60->wsSession().SetPointerCursorMode(EPointerCursorNone); +#ifdef Q_WS_S60 + // Clear CBA + CEikonEnv::Static()->AppUiFactory()->SwapButtonGroup(0); + delete S60->buttonGroupContainer(); + S60->setButtonGroupContainer(0); +#endif + if (S60->qtOwnsS60Environment) { // Restore the S60 framework trap handler. See qt_init(). User::SetTrapHandler(S60->s60InstalledTrapHandler); diff --git a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h index efe045c..60cdfb9 100644 --- a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h +++ b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h @@ -161,7 +161,7 @@ QT_END_NAMESPACE bool handled = false; // sometimes need to redirect mouse events to the popup. QWidget *popup = qAppInstance()->activePopupWidget(); - if (popup) { + if (popup && popup != widget) { switch([event type]) { case NSLeftMouseDown: diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm index 515c6d3..dc926e0 100644 --- a/src/gui/kernel/qeventdispatcher_mac.mm +++ b/src/gui/kernel/qeventdispatcher_mac.mm @@ -844,7 +844,7 @@ static void setChildrenWorksWhenModal(QWidget *widget, bool worksWhenModal) NSWindow *window = qt_mac_window_for(dialogs[i]); if (window && [window isKindOfClass:[NSPanel class]]) { [static_cast<NSPanel *>(window) setWorksWhenModal:worksWhenModal]; - if (worksWhenModal && dialogs[i]->isVisible()){ + if (worksWhenModal && [window isVisible]){ [window orderFront:window]; } } @@ -856,6 +856,7 @@ void QEventDispatcherMacPrivate::updateChildrenWorksWhenModal() // Make the dialog children of the widget // active. And make the dialog children of // the previous modal dialog unactive again: + QMacCocoaAutoReleasePool pool; int size = cocoaModalSessionStack.size(); if (size > 0){ if (QWidget *prevModal = cocoaModalSessionStack[size-1].widget) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index bcddae5..059140e 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -2825,23 +2825,31 @@ void QWidgetPrivate::setSubWindowStacking(bool set) if (NSWindow *pwin = [qt_mac_nativeview_for(parent) window]) { if (set) { Qt::WindowType ptype = parent->window()->windowType(); - if ([pwin isVisible] && (ptype == Qt::Window || ptype == Qt::Dialog) && ![qwin parentWindow]) + if ([pwin isVisible] && (ptype == Qt::Window || ptype == Qt::Dialog) && ![qwin parentWindow]) { + NSInteger level = [qwin level]; [pwin addChildWindow:qwin ordered:NSWindowAbove]; + if ([qwin level] < level) + [qwin setLevel:level]; + } } else { [pwin removeChildWindow:qwin]; } } } - QList<QWidget *> widgets = q->findChildren<QWidget *>(); + QObjectList widgets = q->children(); for (int i=0; i<widgets.size(); ++i) { - QWidget *child = widgets.at(i); + QWidget *child = qobject_cast<QWidget *>(widgets.at(i)); if (child && child->isWindow()) { if (NSWindow *cwin = [qt_mac_nativeview_for(child) window]) { if (set) { Qt::WindowType ctype = child->window()->windowType(); - if ([cwin isVisible] && (ctype == Qt::Window || ctype == Qt::Dialog) && ![cwin parentWindow]) + if ([cwin isVisible] && (ctype == Qt::Window || ctype == Qt::Dialog) && ![cwin parentWindow]) { + NSInteger level = [cwin level]; [qwin addChildWindow:cwin ordered:NSWindowAbove]; + if ([cwin level] < level) + [cwin setLevel:level]; + } } else { [qwin removeChildWindow:qt_mac_window_for(child)]; } diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 13b48e9..9543792 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -508,7 +508,7 @@ void QWidgetPrivate::show_sys() CEikButtonGroupContainer *cba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal,ui,R_AVKON_SOFTKEYS_EMPTY_WITH_IDS); - CEikButtonGroupContainer *oldCba = CEikonEnv::Static()->AppUiFactory()->SwapButtonGroup(cba); + CEikButtonGroupContainer *oldCba = factory->SwapButtonGroup(cba); Q_ASSERT(!oldCba); S60->setButtonGroupContainer(cba); @@ -517,7 +517,7 @@ void QWidgetPrivate::show_sys() menuBar->SetMenuType(CEikMenuBar::EMenuOptions); S60->appUi()->AddToStackL(menuBar,ECoeStackPriorityMenu,ECoeStackFlagRefusesFocus); - CEikMenuBar *oldMenu = CEikonEnv::Static()->AppUiFactory()->SwapMenuBar(menuBar); + CEikMenuBar *oldMenu = factory->SwapMenuBar(menuBar); Q_ASSERT(!oldMenu); ) diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri index 099619c..51f2538 100644 --- a/src/gui/painting/painting.pri +++ b/src/gui/painting/painting.pri @@ -34,6 +34,7 @@ HEADERS += \ painting/qprinter.h \ painting/qprinter_p.h \ painting/qprinterinfo.h \ + painting/qprinterinfo_p.h \ painting/qrasterizer_p.h \ painting/qregion.h \ painting/qstroker_p.h \ @@ -73,6 +74,7 @@ SOURCES += \ painting/qprintengine_pdf.cpp \ painting/qprintengine_ps.cpp \ painting/qprinter.cpp \ + painting/qprinterinfo.cpp \ painting/qrasterizer.cpp \ painting/qregion.cpp \ painting/qstroker.cpp \ diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 024a69d..62af212 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -7711,17 +7711,6 @@ void qInitDrawhelperAsm() } #endif #endif // SSE -#if defined(QT_HAVE_MMXEXT) && defined(QT_HAVE_SSE) - } else if (features & MMXEXT) { - qt_memfill32 = qt_memfill32_sse; - qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse; -# ifdef QT_HAVE_3DNOW - if (features & MMX3DNOW) { - qt_memfill32 = qt_memfill32_sse3dnow; - qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse3dnow; - } -# endif // 3DNOW -#endif // MMXEXT } #ifdef QT_HAVE_MMX if (features & MMX) { diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 0cc2e40..33fd21e 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -1684,9 +1684,7 @@ QT_TRIVIAL_MEMCONVERT_IMPL(qrgb888) QT_TRIVIAL_MEMCONVERT_IMPL(qargb6666) QT_TRIVIAL_MEMCONVERT_IMPL(qrgb666) QT_TRIVIAL_MEMCONVERT_IMPL(quint16) -#ifdef Q_WS_QWS QT_TRIVIAL_MEMCONVERT_IMPL(qrgb565) -#endif QT_TRIVIAL_MEMCONVERT_IMPL(qargb8565) QT_TRIVIAL_MEMCONVERT_IMPL(qargb8555) QT_TRIVIAL_MEMCONVERT_IMPL(qrgb555) @@ -1783,9 +1781,7 @@ QT_RECTCONVERT_TRIVIAL_IMPL(quint32) QT_RECTCONVERT_TRIVIAL_IMPL(qrgb888) QT_RECTCONVERT_TRIVIAL_IMPL(qargb6666) QT_RECTCONVERT_TRIVIAL_IMPL(qrgb666) -#ifdef Q_WS_QWS QT_RECTCONVERT_TRIVIAL_IMPL(qrgb565) -#endif QT_RECTCONVERT_TRIVIAL_IMPL(qargb8565) QT_RECTCONVERT_TRIVIAL_IMPL(quint16) QT_RECTCONVERT_TRIVIAL_IMPL(qargb8555) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 97dfddf..dd14e66 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -1211,7 +1211,7 @@ void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) // There are some cases that are not supported by clip(QRect) if (op != Qt::UniteClip && (op != Qt::IntersectClip || !s->clip || s->clip->hasRectClip || s->clip->hasRegionClip)) { - if (s->matrix.type() <= QTransform::TxTranslate + if (s->matrix.type() <= QTransform::TxScale && ((path.shape() == QVectorPath::RectangleHint) || (isRect(points, path.elementCount()) && (!types || (types[0] == QPainterPath::MoveToElement @@ -1223,8 +1223,8 @@ void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) #endif QRectF r(points[0], points[1], points[4]-points[0], points[5]-points[1]); - clip(r.toRect(), op); - return; + if (setClipRectInDeviceCoords(s->matrix.mapRect(r).toRect(), op)) + return; } } @@ -1285,7 +1285,6 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) qDebug() << "QRasterPaintEngine::clip(): " << rect << op; #endif - Q_D(QRasterPaintEngine); QRasterPaintEngineState *s = state(); if (op == Qt::NoClip) { @@ -1295,11 +1294,23 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) QPaintEngineEx::clip(rect, op); return; - } else if (op == Qt::ReplaceClip || s->clip == 0) { + } else if (!setClipRectInDeviceCoords(s->matrix.mapRect(rect), op)) { + QPaintEngineEx::clip(rect, op); + return; + } +} + + +bool QRasterPaintEngine::setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op) +{ + Q_D(QRasterPaintEngine); + QRect clipRect = r & d->deviceRect; + QRasterPaintEngineState *s = state(); + + if (op == Qt::ReplaceClip || s->clip == 0) { // No current clip, hence we intersect with sysclip and be // done with it... - QRect clipRect = s->matrix.mapRect(rect) & d->deviceRect; QRegion clipRegion = systemClip(); QClipData *clip = new QClipData(d->rasterBuffer->height()); @@ -1315,12 +1326,11 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) s->clip->enabled = true; s->flags.has_clip_ownership = true; - } else { // intersect clip with current clip + } else if (op == Qt::IntersectClip){ // intersect clip with current clip QClipData *base = s->clip; Q_ASSERT(base); if (base->hasRectClip || base->hasRegionClip) { - QRect clipRect = s->matrix.mapRect(rect) & d->deviceRect; if (!s->flags.has_clip_ownership) { s->clip = new QClipData(d->rasterBuffer->height()); s->flags.has_clip_ownership = true; @@ -1331,11 +1341,14 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) s->clip->setClipRegion(base->clipRegion & clipRect); s->clip->enabled = true; } else { - QPaintEngineEx::clip(rect, op); - return; + return false; } + } else { + return false; } + qrasterpaintengine_dirty_clip(d, s); + return true; } diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index 404528c..d70a7e7 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -268,6 +268,8 @@ private: void drawGlyphsS60(const QPointF &p, const QTextItemInt &ti); #endif // Q_OS_SYMBIAN && QT_NO_FREETYPE + bool setClipRectInDeviceCoords(const QRect &r, Qt::ClipOperation op); + inline void ensureBrush(const QBrush &brush) { if (!qbrush_fast_equals(state()->lastBrush, brush) || (brush.style() != Qt::NoBrush && state()->fillFlags)) updateBrush(brush); diff --git a/src/gui/painting/qprinterinfo.qdoc b/src/gui/painting/qprinterinfo.cpp index 9193213..72f8be3 100644 --- a/src/gui/painting/qprinterinfo.qdoc +++ b/src/gui/painting/qprinterinfo.cpp @@ -25,6 +25,16 @@ ** ****************************************************************************/ +#include "qprinterinfo.h" +#include "qprinterinfo_p.h" + +#ifndef QT_NO_PRINTER + +QT_BEGIN_NAMESPACE + +QPrinterInfoPrivate QPrinterInfoPrivate::shared_null; + + /*! \class QPrinterInfo @@ -59,60 +69,94 @@ */ /*! - \fn QPrinterInfo::QPrinterInfo() - Constructs an empty QPrinterInfo object. \sa isNull() */ +QPrinterInfo::QPrinterInfo() + : d_ptr(&QPrinterInfoPrivate::shared_null) +{ +} /*! - \fn QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) - - Constructs a copy of \a src. + Constructs a copy of \a other. */ +QPrinterInfo::QPrinterInfo(const QPrinterInfo &other) + : d_ptr(new QPrinterInfoPrivate(*other.d_ptr)) +{ +} /*! - \fn QPrinterInfo::QPrinterInfo(const QPrinter& printer) - Constructs a QPrinterInfo object from \a printer. */ +QPrinterInfo::QPrinterInfo(const QPrinter &printer) + : d_ptr(&QPrinterInfoPrivate::shared_null) +{ + foreach (const QPrinterInfo &printerInfo, availablePrinters()) { + if (printerInfo.printerName() == printer.printerName()) { + d_ptr.reset(new QPrinterInfoPrivate(*printerInfo.d_ptr)); + break; + } + } +} /*! - \fn QPrinterInfo::~QPrinterInfo() + \internal +*/ +QPrinterInfo::QPrinterInfo(const QString &name) + : d_ptr(new QPrinterInfoPrivate(name)) +{ +} +/*! Destroys the QPrinterInfo object. References to the values in the object become invalid. */ +QPrinterInfo::~QPrinterInfo() +{ +} /*! - \fn QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) - - Sets the QPrinterInfo object to be equal to \a src. + Sets the QPrinterInfo object to be equal to \a other. */ +QPrinterInfo &QPrinterInfo::operator=(const QPrinterInfo &other) +{ + Q_ASSERT(d_ptr); + d_ptr.reset(new QPrinterInfoPrivate(*other.d_ptr)); + return *this; +} /*! - \fn QString QPrinterInfo::printerName() const - Returns the name of the printer. \sa QPrinter::setPrinterName() */ +QString QPrinterInfo::printerName() const +{ + const Q_D(QPrinterInfo); + return d->name; +} /*! - \fn bool QPrinterInfo::isNull() const - Returns whether this QPrinterInfo object holds a printer definition. An empty QPrinterInfo object could result for example from calling defaultPrinter() when there are no printers on the system. */ +bool QPrinterInfo::isNull() const +{ + const Q_D(QPrinterInfo); + return d == &QPrinterInfoPrivate::shared_null; +} /*! - \fn bool QPrinterInfo::isDefault() const - Returns whether this printer is the default printer. */ +bool QPrinterInfo::isDefault() const +{ + const Q_D(QPrinterInfo); + return d->isDefault; +} /*! \fn QList< QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const @@ -123,3 +167,7 @@ Not all printer drivers support this query, so the list may be empty. On Mac OS X 10.3, this function always returns an empty list. */ + +QT_END_NAMESPACE + +#endif // QT_NO_PRINTER diff --git a/src/gui/painting/qprinterinfo.h b/src/gui/painting/qprinterinfo.h index 063c6b9..c8c9534 100644 --- a/src/gui/painting/qprinterinfo.h +++ b/src/gui/painting/qprinterinfo.h @@ -42,9 +42,10 @@ #ifndef QPRINTERINFO_H #define QPRINTERINFO_H -#include <QtGui/QPrinter> #include <QtCore/QList> +#include <QtGui/QPrinter> + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -56,15 +57,13 @@ class QPrinterInfoPrivate; class QPrinterInfoPrivateDeleter; class Q_GUI_EXPORT QPrinterInfo { -Q_DECLARE_PRIVATE(QPrinterInfo) - public: QPrinterInfo(); - QPrinterInfo(const QPrinterInfo& src); - QPrinterInfo(const QPrinter& printer); + QPrinterInfo(const QPrinterInfo &other); + QPrinterInfo(const QPrinter &printer); ~QPrinterInfo(); - QPrinterInfo& operator=(const QPrinterInfo& src); + QPrinterInfo &operator=(const QPrinterInfo &other); QString printerName() const; bool isNull() const; @@ -75,8 +74,10 @@ public: static QPrinterInfo defaultPrinter(); private: - QPrinterInfo(const QString& name); + QPrinterInfo(const QString &name); +private: + Q_DECLARE_PRIVATE(QPrinterInfo) QScopedPointer<QPrinterInfoPrivate, QPrinterInfoPrivateDeleter> d_ptr; }; diff --git a/src/gui/painting/qprinterinfo_mac.cpp b/src/gui/painting/qprinterinfo_mac.cpp index 9b199f4..033682a 100644 --- a/src/gui/painting/qprinterinfo_mac.cpp +++ b/src/gui/painting/qprinterinfo_mac.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qprinterinfo.h" +#include "qprinterinfo_p.h" #include "private/qt_mac_p.h" @@ -47,189 +48,71 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_PRINTER -class QPrinterInfoPrivate -{ -Q_DECLARE_PUBLIC(QPrinterInfo) -public: - ~QPrinterInfoPrivate(); - QPrinterInfoPrivate(); - QPrinterInfoPrivate(const QString& name); - -private: - QPrinterInfo* q_ptr; - - QString m_name; - bool m_default; - bool m_isNull; -}; - -static QPrinterInfoPrivate nullQPrinterInfoPrivate; - -class QPrinterInfoPrivateDeleter -{ -public: - static inline void cleanup(QPrinterInfoPrivate *d) - { - if (d != &nullQPrinterInfoPrivate) - delete d; - } -}; - -extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size); - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// +extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF &size); QList<QPrinterInfo> QPrinterInfo::availablePrinters() { QList<QPrinterInfo> printers; - OSStatus status = noErr; - QCFType<CFArrayRef> printerList; - status = PMServerCreatePrinterList(kPMServerLocal, &printerList); - if (status == noErr) { - CFIndex count = CFArrayGetCount(printerList); - for (CFIndex i=0; i<count; ++i) { - PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i))); - QString name = QCFString::toQString(PMPrinterGetName(printer)); - printers.append(QPrinterInfo(name)); - if (PMPrinterIsDefault(printer)) { - printers[i].d_ptr->m_default = true; - } + QCFType<CFArrayRef> array; + if (PMServerCreatePrinterList(kPMServerLocal, &array) == noErr) { + CFIndex count = CFArrayGetCount(array); + for (int i = 0; i < count; ++i) { + PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(array, i))); + QString printerName = QCFString::toQString(PMPrinterGetName(printer)); + + QPrinterInfo printerInfo(printerName); + if (PMPrinterIsDefault(printer)) + printerInfo.d_ptr->isDefault = true; + printers.append(printerInfo); } } return printers; } -QPrinterInfo QPrinterInfo::defaultPrinter(){ - QList<QPrinterInfo> printers = availablePrinters(); - for (int c = 0; c < printers.size(); ++c) { - if (printers[c].isDefault()) { - return printers[c]; - } - } - return QPrinterInfo(); -} - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -QPrinterInfo::QPrinterInfo(const QPrinter& prn) - : d_ptr(&nullQPrinterInfoPrivate) +QPrinterInfo QPrinterInfo::defaultPrinter() { - QList<QPrinterInfo> list = availablePrinters(); - for (int c = 0; c < list.size(); ++c) { - if (prn.printerName() == list[c].printerName()) { - *this = list[c]; - return; - } + QList<QPrinterInfo> printers = availablePrinters(); + foreach (const QPrinterInfo &printerInfo, printers) { + if (printerInfo.isDefault()) + return printerInfo; } -} - -QPrinterInfo::~QPrinterInfo() -{ -} - -QPrinterInfo::QPrinterInfo() - : d_ptr(&nullQPrinterInfoPrivate) -{ -} - -QPrinterInfo::QPrinterInfo(const QString& name) - : d_ptr(new QPrinterInfoPrivate(name)) -{ - d_ptr->q_ptr = this; -} - -QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) - : d_ptr(&nullQPrinterInfoPrivate) -{ - *this = src; -} - -QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) -{ - Q_ASSERT(d_ptr); - d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); - d_ptr->q_ptr = this; - return *this; -} - -QString QPrinterInfo::printerName() const -{ - const Q_D(QPrinterInfo); - return d->m_name; -} -bool QPrinterInfo::isNull() const -{ - const Q_D(QPrinterInfo); - return d->m_isNull; -} - -bool QPrinterInfo::isDefault() const -{ - const Q_D(QPrinterInfo); - return d->m_default; + return printers.value(0); } QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const { const Q_D(QPrinterInfo); - PMPrinter cfPrn = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(d->m_name)); + QList<QPrinter::PaperSize> paperSizes; + if (isNull()) + return paperSizes; - if (!cfPrn) return QList<QPrinter::PaperSize>(); + PMPrinter cfPrn = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(d->name)); + if (!cfPrn) + return paperSizes; CFArrayRef array; - OSStatus status = PMPrinterGetPaperList(cfPrn, &array); - - if (status != 0) { + if (PMPrinterGetPaperList(cfPrn, &array) != noErr) { PMRelease(cfPrn); - return QList<QPrinter::PaperSize>(); + return paperSizes; } - QList<QPrinter::PaperSize> paperList; int count = CFArrayGetCount(array); - for (int c = 0; c < count; c++) { - PMPaper paper = static_cast<PMPaper>( - const_cast<void*>( - CFArrayGetValueAtIndex(array, c))); + for (int i = 0; i < count; ++i) { + PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(array, i))); double width, height; - status = PMPaperGetWidth(paper, &width); - status |= PMPaperGetHeight(paper, &height); - if (status != 0) continue; - - QSizeF size(width * 0.3527, height * 0.3527); - paperList.append(qSizeFTopaperSize(size)); + if (PMPaperGetWidth(paper, &width) == noErr && PMPaperGetHeight(paper, &height) == noErr) { + QSizeF size(width * 0.3527, height * 0.3527); + paperSizes.append(qSizeFTopaperSize(size)); + } } PMRelease(cfPrn); - return paperList; -} - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -QPrinterInfoPrivate::QPrinterInfoPrivate() : - q_ptr(NULL), - m_default(false), - m_isNull(true) -{ -} - -QPrinterInfoPrivate::QPrinterInfoPrivate(const QString& name) : - q_ptr(NULL), - m_name(name), - m_default(false), - m_isNull(false) -{ -} - -QPrinterInfoPrivate::~QPrinterInfoPrivate() -{ + return paperSizes; } #endif // QT_NO_PRINTER diff --git a/src/gui/painting/qprinterinfo_p.h b/src/gui/painting/qprinterinfo_p.h new file mode 100644 index 0000000..7781d59 --- /dev/null +++ b/src/gui/painting/qprinterinfo_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPRINTERINFO_P_H +#define QPRINTERINFO_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "QtCore/qglobal.h" + +#ifndef QT_NO_PRINTER + +#include "QtCore/qlist.h" + +QT_BEGIN_NAMESPACE + +class QPrinterInfoPrivate +{ +public: + QPrinterInfoPrivate(const QString& name = QString()) : + name(name), isDefault(false) +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA) +#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) + , cupsPrinterIndex(0), hasPaperSizes(false) +#endif +#endif + {} + ~QPrinterInfoPrivate() + {} + + static QPrinterInfoPrivate shared_null; + + QString name; + bool isDefault; + +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA) +#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) + int cupsPrinterIndex; + mutable bool hasPaperSizes; + mutable QList<QPrinter::PaperSize> paperSizes; +#endif +#endif +}; + + +class QPrinterInfoPrivateDeleter +{ +public: + static inline void cleanup(QPrinterInfoPrivate *d) + { + if (d != &QPrinterInfoPrivate::shared_null) + delete d; + } +}; + +QT_END_NAMESPACE + +#endif // QT_NO_PRINTER + +#endif // QPRINTERINFO_P_H diff --git a/src/gui/painting/qprinterinfo_unix.cpp b/src/gui/painting/qprinterinfo_unix.cpp index 2129aa5..af2e52a 100644 --- a/src/gui/painting/qprinterinfo_unix.cpp +++ b/src/gui/painting/qprinterinfo_unix.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qprinterinfo.h" +#include "qprinterinfo_p.h" #include <qfile.h> #include <qfileinfo.h> @@ -60,42 +61,66 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_PRINTER -class QPrinterInfoPrivate -{ -Q_DECLARE_PUBLIC(QPrinterInfo) -public: - QPrinterInfoPrivate(); - QPrinterInfoPrivate(const QString& name); - ~QPrinterInfoPrivate(); - - static QPrinter::PaperSize string2PaperSize(const QString& str); - static QString pageSize2String(QPrinter::PaperSize size); - -private: - QString m_name; - bool m_isNull; - bool m_default; - mutable bool m_mustGetPaperSizes; - mutable QList<QPrinter::PaperSize> m_paperSizes; - int m_cupsPrinterIndex; - - QPrinterInfo* q_ptr; +#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) +// preserver names in ascending order for the binary search +static const struct NamedPaperSize { + const char *const name; + QPrinter::PaperSize size; +} named_sizes_map[QPrinter::NPageSize] = { + { "A0", QPrinter::A0 }, + { "A1", QPrinter::A1 }, + { "A2", QPrinter::A2 }, + { "A3", QPrinter::A3 }, + { "A4", QPrinter::A4 }, + { "A5", QPrinter::A5 }, + { "A6", QPrinter::A6 }, + { "A7", QPrinter::A7 }, + { "A8", QPrinter::A8 }, + { "A9", QPrinter::A9 }, + { "B0", QPrinter::B0 }, + { "B1", QPrinter::B1 }, + { "B10", QPrinter::B10 }, + { "B2", QPrinter::B2 }, + { "B4", QPrinter::B4 }, + { "B5", QPrinter::B5 }, + { "B6", QPrinter::B6 }, + { "B7", QPrinter::B7 }, + { "B8", QPrinter::B8 }, + { "B9", QPrinter::B9 }, + { "C5E", QPrinter::C5E }, + { "Comm10E", QPrinter::Comm10E }, + { "Custom", QPrinter::Custom }, + { "DLE", QPrinter::DLE }, + { "Executive", QPrinter::Executive }, + { "Folio", QPrinter::Folio }, + { "Ledger", QPrinter::Ledger }, + { "Legal", QPrinter::Legal }, + { "Letter", QPrinter::Letter }, + { "Tabloid", QPrinter::Tabloid } }; -static QPrinterInfoPrivate nullQPrinterInfoPrivate; +inline bool operator<(const char *name, const NamedPaperSize &data) +{ return qstrcmp(name, data.name) < 0; } +inline bool operator<(const NamedPaperSize &data, const char *name) +{ return qstrcmp(data.name, name) < 0; } -class QPrinterInfoPrivateDeleter +static inline QPrinter::PaperSize string2PaperSize(const char *name) { -public: - static inline void cleanup(QPrinterInfoPrivate *d) - { - if (d != &nullQPrinterInfoPrivate) - delete d; - } -}; + const NamedPaperSize *r = qBinaryFind(named_sizes_map, named_sizes_map + QPrinter::NPageSize, name); + if (r - named_sizes_map != QPrinter::NPageSize) + return r->size; + return QPrinter::Custom; +} -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// +static inline const char *paperSize2String(QPrinter::PaperSize size) +{ + for (int i = 0; i < QPrinter::NPageSize; ++i) { + if (size == named_sizes_map[i].size) + return named_sizes_map[i].name; + } + return 0; +} +#endif void qt_perhapsAddPrinter(QList<QPrinterDescription> *printers, const QString &name, QString host, QString comment, @@ -784,12 +809,12 @@ int qt_getLprPrinters(QList<QPrinterDescription>& printers) #endif } + QRegExp ps(QLatin1String("[^a-z]ps(?:[^a-z]|$)")); + QRegExp lp(QLatin1String("[^a-z]lp(?:[^a-z]|$)")); + int quality = 0; int best = 0; for (int i = 0; i < printers.size(); ++i) { - QRegExp ps(QLatin1String("[^a-z]ps(?:[^a-z]|$)")); - QRegExp lp(QLatin1String("[^a-z]lp(?:[^a-z]|$)")); - QString name = printers.at(i).name; QString comment = printers.at(i).comment; if (quality < 5 && name == dollarPrinter) { @@ -824,331 +849,77 @@ int qt_getLprPrinters(QList<QPrinterDescription>& printers) QList<QPrinterInfo> QPrinterInfo::availablePrinters() { - QList<QPrinterInfo> list; + QList<QPrinterInfo> printers; #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) - QCUPSSupport cups; if (QCUPSSupport::isAvailable()) { - //const ppd_file_t* cupsPPD = cups.currentPPD(); + QCUPSSupport cups; int cupsPrinterCount = cups.availablePrintersCount(); const cups_dest_t* cupsPrinters = cups.availablePrinters(); - for (int i = 0; i < cupsPrinterCount; ++i) { QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name)); if (cupsPrinters[i].instance) printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance); - list.append(QPrinterInfo(printerName)); + + QPrinterInfo printerInfo(printerName); if (cupsPrinters[i].is_default) - list[i].d_ptr->m_default = true; - list[i].d_ptr->m_cupsPrinterIndex = i; + printerInfo.d_ptr->isDefault = true; + printerInfo.d_ptr->cupsPrinterIndex = i; + printers.append(printerInfo); } - } else { + } else #endif + { QList<QPrinterDescription> lprPrinters; int defprn = qt_getLprPrinters(lprPrinters); // populating printer combo - QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin(); - for(; i != lprPrinters.constEnd(); ++i) { - list.append(QPrinterInfo((*i).name)); - } - if (defprn >= 0 && defprn < lprPrinters.size()) { - list[defprn].d_ptr->m_default = true; - } -#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) + foreach (const QPrinterDescription &description, lprPrinters) + printers.append(QPrinterInfo(description.name)); + if (defprn >= 0 && defprn < printers.size()) + printers[defprn].d_ptr->isDefault = true; } -#endif - return list; + return printers; } QPrinterInfo QPrinterInfo::defaultPrinter() { - QList<QPrinterInfo> prnList = availablePrinters(); - for (int i = 0; i < prnList.size(); ++i) { - if (prnList[i].isDefault()) - return prnList[i]; + QList<QPrinterInfo> printers = availablePrinters(); + foreach (const QPrinterInfo &printerInfo, printers) { + if (printerInfo.isDefault()) + return printerInfo; } - return (prnList.size() > 0) ? prnList[0] : QPrinterInfo(); -} - -QPrinterInfo::QPrinterInfo() - : d_ptr(&nullQPrinterInfoPrivate) -{ -} -QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) - : d_ptr(&nullQPrinterInfoPrivate) -{ - *this = src; + return printers.value(0); } -QPrinterInfo::QPrinterInfo(const QPrinter& printer) - : d_ptr(new QPrinterInfoPrivate(printer.printerName())) +QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const { - - Q_D(QPrinterInfo); - d->q_ptr = this; - #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) - QCUPSSupport cups; - if (QCUPSSupport::isAvailable()) { - int cupsPrinterCount = cups.availablePrintersCount(); - const cups_dest_t* cupsPrinters = cups.availablePrinters(); - - for (int i = 0; i < cupsPrinterCount; ++i) { - QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name)); - if (cupsPrinters[i].instance) - printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance); - if (printerName == printer.printerName()) { - if (cupsPrinters[i].is_default) - d->m_default = true; - d->m_cupsPrinterIndex = i; - return; - } - } - } else { -#endif - QList<QPrinterDescription> lprPrinters; - int defprn = qt_getLprPrinters(lprPrinters); - // populating printer combo - QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin(); - int c; - for(c = 0; i != lprPrinters.constEnd(); ++i, ++c) { - if (i->name == printer.printerName()) { - if (defprn == c) - d->m_default = true; - return; - } - } -#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) - } -#endif - - // Printer not found. - d_ptr.reset(&nullQPrinterInfoPrivate); -} - -QPrinterInfo::QPrinterInfo(const QString& name) - : d_ptr(new QPrinterInfoPrivate(name)) -{ - d_ptr->q_ptr = this; -} - -QPrinterInfo::~QPrinterInfo() -{ -} - -QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) -{ - Q_ASSERT(d_ptr); - d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); - d_ptr->q_ptr = this; - return *this; -} - -QString QPrinterInfo::printerName() const -{ const Q_D(QPrinterInfo); - return d->m_name; -} - -bool QPrinterInfo::isNull() const -{ - const Q_D(QPrinterInfo); - return d->m_isNull; -} -bool QPrinterInfo::isDefault() const -{ - const Q_D(QPrinterInfo); - return d->m_default; -} + if (isNull()) + return d->paperSizes; -QList< QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const -{ - const Q_D(QPrinterInfo); - if (d->m_mustGetPaperSizes) { - d->m_mustGetPaperSizes = false; + if (!d->hasPaperSizes) { + d->hasPaperSizes = true; -#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) - QCUPSSupport cups; if (QCUPSSupport::isAvailable()) { // Find paper sizes from CUPS. - cups.setCurrentPrinter(d->m_cupsPrinterIndex); + QCUPSSupport cups; + cups.setCurrentPrinter(d->cupsPrinterIndex); const ppd_option_t* sizes = cups.pageSizes(); if (sizes) { - for (int j = 0; j < sizes->num_choices; ++j) { - d->m_paperSizes.append( - QPrinterInfoPrivate::string2PaperSize( - QLatin1String(sizes->choices[j].choice))); - } + for (int j = 0; j < sizes->num_choices; ++j) + d->paperSizes.append(string2PaperSize(sizes->choices[j].choice)); } } -#endif - } - return d->m_paperSizes; -} - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -QPrinterInfoPrivate::QPrinterInfoPrivate() -{ - m_isNull = true; - m_default = false; - m_mustGetPaperSizes = true; - m_cupsPrinterIndex = 0; - q_ptr = 0; -} - -QPrinterInfoPrivate::QPrinterInfoPrivate(const QString& name) -{ - m_name = name; - m_isNull = false; - m_default = false; - m_mustGetPaperSizes = true; - m_cupsPrinterIndex = 0; - q_ptr = 0; -} -QPrinterInfoPrivate::~QPrinterInfoPrivate() -{ -} - -QPrinter::PaperSize QPrinterInfoPrivate::string2PaperSize(const QString& str) -{ - if (str == QLatin1String("A4")) { - return QPrinter::A4; - } else if (str == QLatin1String("B5")) { - return QPrinter::B5; - } else if (str == QLatin1String("Letter")) { - return QPrinter::Letter; - } else if (str == QLatin1String("Legal")) { - return QPrinter::Legal; - } else if (str == QLatin1String("Executive")) { - return QPrinter::Executive; - } else if (str == QLatin1String("A0")) { - return QPrinter::A0; - } else if (str == QLatin1String("A1")) { - return QPrinter::A1; - } else if (str == QLatin1String("A2")) { - return QPrinter::A2; - } else if (str == QLatin1String("A3")) { - return QPrinter::A3; - } else if (str == QLatin1String("A5")) { - return QPrinter::A5; - } else if (str == QLatin1String("A6")) { - return QPrinter::A6; - } else if (str == QLatin1String("A7")) { - return QPrinter::A7; - } else if (str == QLatin1String("A8")) { - return QPrinter::A8; - } else if (str == QLatin1String("A9")) { - return QPrinter::A9; - } else if (str == QLatin1String("B0")) { - return QPrinter::B0; - } else if (str == QLatin1String("B1")) { - return QPrinter::B1; - } else if (str == QLatin1String("B10")) { - return QPrinter::B10; - } else if (str == QLatin1String("B2")) { - return QPrinter::B2; - } else if (str == QLatin1String("B3")) { - return QPrinter::B3; - } else if (str == QLatin1String("B4")) { - return QPrinter::B4; - } else if (str == QLatin1String("B6")) { - return QPrinter::B6; - } else if (str == QLatin1String("B7")) { - return QPrinter::B7; - } else if (str == QLatin1String("B8")) { - return QPrinter::B8; - } else if (str == QLatin1String("B9")) { - return QPrinter::B9; - } else if (str == QLatin1String("C5E")) { - return QPrinter::C5E; - } else if (str == QLatin1String("Comm10E")) { - return QPrinter::Comm10E; - } else if (str == QLatin1String("DLE")) { - return QPrinter::DLE; - } else if (str == QLatin1String("Folio")) { - return QPrinter::Folio; - } else if (str == QLatin1String("Ledger")) { - return QPrinter::Ledger; - } else if (str == QLatin1String("Tabloid")) { - return QPrinter::Tabloid; - } else { - return QPrinter::Custom; - } -} - -QString QPrinterInfoPrivate::pageSize2String(QPrinter::PaperSize size) -{ - switch (size) { - case QPrinter::A4: - return QLatin1String("A4"); - case QPrinter::B5: - return QLatin1String("B5"); - case QPrinter::Letter: - return QLatin1String("Letter"); - case QPrinter::Legal: - return QLatin1String("Legal"); - case QPrinter::Executive: - return QLatin1String("Executive"); - case QPrinter::A0: - return QLatin1String("A0"); - case QPrinter::A1: - return QLatin1String("A1"); - case QPrinter::A2: - return QLatin1String("A2"); - case QPrinter::A3: - return QLatin1String("A3"); - case QPrinter::A5: - return QLatin1String("A5"); - case QPrinter::A6: - return QLatin1String("A6"); - case QPrinter::A7: - return QLatin1String("A7"); - case QPrinter::A8: - return QLatin1String("A8"); - case QPrinter::A9: - return QLatin1String("A9"); - case QPrinter::B0: - return QLatin1String("B0"); - case QPrinter::B1: - return QLatin1String("B1"); - case QPrinter::B10: - return QLatin1String("B10"); - case QPrinter::B2: - return QLatin1String("B2"); - case QPrinter::B3: - return QLatin1String("B3"); - case QPrinter::B4: - return QLatin1String("B4"); - case QPrinter::B6: - return QLatin1String("B6"); - case QPrinter::B7: - return QLatin1String("B7"); - case QPrinter::B8: - return QLatin1String("B8"); - case QPrinter::B9: - return QLatin1String("B9"); - case QPrinter::C5E: - return QLatin1String("C5E"); - case QPrinter::Comm10E: - return QLatin1String("Comm10E"); - case QPrinter::DLE: - return QLatin1String("DLE"); - case QPrinter::Folio: - return QLatin1String("Folio"); - case QPrinter::Ledger: - return QLatin1String("Ledger"); - case QPrinter::Tabloid: - return QLatin1String("Tabloid"); - default: - return QLatin1String("Custom"); - } + return d->paperSizes; +#else + return QList<QPrinter::PaperSize>(); +#endif } #endif // QT_NO_PRINTER diff --git a/src/gui/painting/qprinterinfo_win.cpp b/src/gui/painting/qprinterinfo_win.cpp index caada1f..2d25063 100644 --- a/src/gui/painting/qprinterinfo_win.cpp +++ b/src/gui/painting/qprinterinfo_win.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qprinterinfo.h" +#include "qprinterinfo_p.h" #include <qstringlist.h> @@ -51,59 +52,25 @@ QT_BEGIN_NAMESPACE extern QPrinter::PaperSize mapDevmodePaperSize(int s); -class QPrinterInfoPrivate -{ -Q_DECLARE_PUBLIC(QPrinterInfo) -public: - ~QPrinterInfoPrivate(); - QPrinterInfoPrivate(); - QPrinterInfoPrivate(const QString& name); - -private: - QString m_name; - bool m_default; - bool m_isNull; - - QPrinterInfo* q_ptr; -}; - -static QPrinterInfoPrivate nullQPrinterInfoPrivate; - -class QPrinterInfoPrivateDeleter -{ -public: - static inline void cleanup(QPrinterInfoPrivate *d) - { - if (d != &nullQPrinterInfoPrivate) - delete d; - } -}; - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - QList<QPrinterInfo> QPrinterInfo::availablePrinters() { QList<QPrinterInfo> printers; - LPBYTE buffer; + DWORD needed = 0; DWORD returned = 0; - - if ( !EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) - { - buffer = new BYTE[needed]; - if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS , NULL, - 4, buffer, needed, &needed, &returned)) - { - delete [] buffer; - return printers; - } - PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer); - QPrinterInfo defPrn = defaultPrinter(); - for (uint i = 0; i < returned; ++i) { - printers.append(QPrinterInfo(QString::fromWCharArray(infoList[i].pPrinterName))); - if (printers.at(i).printerName() == defPrn.printerName()) - printers[i].d_ptr->m_default = true; + if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) { + LPBYTE buffer = new BYTE[needed]; + if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) { + PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer); + QPrinterInfo defPrn = defaultPrinter(); + for (uint i = 0; i < returned; ++i) { + QString printerName(QString::fromWCharArray(infoList[i].pPrinterName)); + + QPrinterInfo printerInfo(printerName); + if (printerInfo.printerName() == defPrn.printerName()) + printerInfo.d_ptr->isDefault = true; + printers.append(printerInfo); + } } delete [] buffer; } @@ -117,127 +84,37 @@ QPrinterInfo QPrinterInfo::defaultPrinter() wchar_t buffer[256]; GetProfileString(L"windows", L"device", (wchar_t*)noPrinters.utf16(), buffer, 256); QString output = QString::fromWCharArray(buffer); - - // Filter out the name of the printer, which should be everything - // before a comma. - bool noConfiguredPrinters = (output == noPrinters); - QStringList info = output.split(QLatin1Char(',')); - QString printerName = noConfiguredPrinters ? QString() : info.at(0); - - QPrinterInfo prn(printerName); - prn.d_ptr->m_default = true; - if (noConfiguredPrinters) - prn.d_ptr->m_isNull = true; - return prn; -} - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -QPrinterInfo::QPrinterInfo() - : d_ptr(&nullQPrinterInfoPrivate) -{ -} - -QPrinterInfo::QPrinterInfo(const QString& name) - : d_ptr(new QPrinterInfoPrivate(name)) -{ - d_ptr->q_ptr = this; -} - -QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) - : d_ptr(&nullQPrinterInfoPrivate) -{ - *this = src; -} - -QPrinterInfo::QPrinterInfo(const QPrinter& prn) - : d_ptr(&nullQPrinterInfoPrivate) -{ - QList<QPrinterInfo> list = availablePrinters(); - for (int c = 0; c < list.size(); ++c) { - if (prn.printerName() == list[c].printerName()) { - *this = list[c]; - return; - } + if (output != noPrinters) { + // Filter out the name of the printer, which should be everything before a comma. + QString printerName = output.split(QLatin1Char(',')).value(0); + QPrinterInfo printerInfo(printerName); + printerInfo.d_ptr->isDefault = true; + return printerInfo; } - *this = QPrinterInfo(); -} - -QPrinterInfo::~QPrinterInfo() -{ -} - -QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) -{ - Q_ASSERT(d_ptr); - d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); - d_ptr->q_ptr = this; - return *this; -} - -QString QPrinterInfo::printerName() const -{ - const Q_D(QPrinterInfo); - return d->m_name; -} - -bool QPrinterInfo::isNull() const -{ - const Q_D(QPrinterInfo); - return d->m_isNull; -} - -bool QPrinterInfo::isDefault() const -{ - const Q_D(QPrinterInfo); - return d->m_default; + return QPrinterInfo(); } QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const { const Q_D(QPrinterInfo); - QList<QPrinter::PaperSize> paperList; - DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->m_name.utf16()), - NULL, DC_PAPERS, NULL, NULL); - if ((int)size == -1) - return paperList; - - wchar_t *papers = new wchar_t[size]; - size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->m_name.utf16()), - NULL, DC_PAPERS, papers, NULL); + QList<QPrinter::PaperSize> paperSizes; + if (isNull()) + return paperSizes; - for (int c = 0; c < (int)size; ++c) { - paperList.append(mapDevmodePaperSize(papers[c])); + DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERS, NULL, NULL); + if ((int)size != -1) { + wchar_t *papers = new wchar_t[size]; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), + NULL, DC_PAPERS, papers, NULL); + for (int c = 0; c < (int)size; ++c) + paperSizes.append(mapDevmodePaperSize(papers[c])); + delete [] papers; } - delete [] papers; - - return paperList; -} - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -QPrinterInfoPrivate::QPrinterInfoPrivate() : - m_default(false), - m_isNull(true), - q_ptr(NULL) -{ -} - -QPrinterInfoPrivate::QPrinterInfoPrivate(const QString& name) : - m_name(name), - m_default(false), - m_isNull(false), - q_ptr(NULL) -{ -} - -QPrinterInfoPrivate::~QPrinterInfoPrivate() -{ + return paperSizes; } #endif // QT_NO_PRINTER diff --git a/src/gui/painting/qunifiedtoolbarsurface_mac.cpp b/src/gui/painting/qunifiedtoolbarsurface_mac.cpp index ace0a46..02ba8db 100644 --- a/src/gui/painting/qunifiedtoolbarsurface_mac.cpp +++ b/src/gui/painting/qunifiedtoolbarsurface_mac.cpp @@ -83,11 +83,11 @@ void QUnifiedToolbarSurface::recursiveRedirect(QObject *object, const QPoint &of widget->d_func()->unifiedSurface = this; widget->d_func()->isInUnifiedToolbar = true; widget->d_func()->toolbar_offset = offset; - } - } - for (int i = 0; i < object->children().size(); ++i) { - recursiveRedirect(object->children().at(i), offset); + for (int i = 0; i < object->children().size(); ++i) { + recursiveRedirect(object->children().at(i), offset); + } + } } } } diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 3326c48..4a19b49 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -104,11 +104,11 @@ const int QS60StylePrivate::m_numberOfLayouts = const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = { // *** generated pixel metrics *** -{5,0,-909,0,0,2,0,0,-1,7,12,22,15,15,7,198,-909,-909,-909,20,13,2,0,0,21,7,18,30,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,4,4,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1,106}, -{5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,8,27,28,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,3,3,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1,106}, -{7,0,-909,0,0,2,0,0,-1,25,69,46,37,37,9,258,-909,-909,-909,23,19,26,0,0,32,25,72,44,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,13,3,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135}, -{7,0,-909,0,0,2,0,0,-1,25,68,46,37,37,9,258,-909,-909,-909,31,19,6,0,0,32,25,60,52,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,12,3,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135}, -{7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,7,32,30,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1,106} +{5,0,-909,0,0,2,0,2,-1,7,12,22,15,15,7,198,-909,-909,-909,20,13,2,0,0,21,7,18,30,3,3,1,-909,-909,0,1,0,0,12,20,15,15,18,18,1,115,18,0,-909,-909,-909,-909,0,0,16,2,-909,0,0,-909,16,-909,-909,-909,-909,32,18,55,24,55,4,4,4,9,13,-909,5,51,11,5,0,3,3,6,8,3,3,-909,2,-909,-909,-909,-909,5,5,3,1,106}, +{5,0,-909,0,0,1,0,2,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,8,27,28,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,3,3,5,10,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,2,-909,-909,-909,-909,6,6,3,1,106}, +{7,0,-909,0,0,2,0,5,-1,25,69,46,37,37,9,258,-909,-909,-909,23,19,26,0,0,32,25,72,44,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,13,3,6,8,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135}, +{7,0,-909,0,0,2,0,5,-1,25,68,46,37,37,9,258,-909,-909,-909,31,19,6,0,0,32,25,60,52,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,96,35,96,12,3,6,8,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,3,-909,-909,-909,-909,7,7,3,1,135}, +{7,0,-909,0,0,2,0,2,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,7,32,30,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1,106} // *** End of generated data *** }; @@ -1071,11 +1071,11 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom // Button frame QStyleOptionFrame buttonOption; buttonOption.QStyleOption::operator=(*cmb); - const int maxHeight = cmbxFrame.height(); - const int maxWidth = cmbxFrame.width() - cmbxEditField.width(); + const int maxButtonSide = cmbxFrame.width() - cmbxEditField.width(); + const int newTop = cmbxEditField.center().y() - maxButtonSide / 2; const int topLeftPoint = direction ? - (cmbxEditField.right() + 1) : (cmbxEditField.left() + 1 - maxWidth); - const QRect buttonRect(topLeftPoint, cmbxEditField.top(), maxWidth, maxHeight); + (cmbxEditField.right() + 1) : (cmbxEditField.left() + 1 - maxButtonSide); + const QRect buttonRect(topLeftPoint, newTop, maxButtonSide, maxButtonSide); buttonOption.rect = buttonRect; buttonOption.state = cmb->state; drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget); @@ -2884,30 +2884,24 @@ QRect QS60Style::subControlRect(ComplexControl control, const QStyleOptionComple ret = cmb->rect; const int width = cmb->rect.width(); const int height = cmb->rect.height(); - const int buttonIconSize = QS60StylePrivate::pixelMetric(PM_ButtonIconSize); const int buttonMargin = cmb->frame ? 2 : 0; // lets use spinbox frame here as well, as no combobox specific value available. const int frameThickness = cmb->frame ? pixelMetric(PM_SpinBoxFrameWidth, cmb, widget) : 0; - const int buttonWidth = qMax(cmb->rect.height(), buttonIconSize); - + const int buttonMinSize = QS60StylePrivate::pixelMetric(PM_ButtonIconSize) + 2 * buttonMargin; QSize buttonSize; - buttonSize.setWidth(buttonWidth + 2 * buttonMargin); - buttonSize.setHeight(qMax(8, (cmb->rect.height() >> 1) - frameThickness)); //buttons should be squares + //allow button to grow to one fourth of the frame height, if the frame is really tall + buttonSize.setHeight(qMin(height, qMax(width / 4, buttonMinSize))); + buttonSize.setWidth(buttonSize.height()); buttonSize = buttonSize.expandedTo(QApplication::globalStrut()); switch (scontrol) { case SC_ComboBoxArrow: { - const int xposMod = cmb->rect.x() + width - buttonMargin - buttonWidth; + const int xposMod = cmb->rect.x() + width - buttonMargin - buttonSize.width(); const int ypos = cmb->rect.y(); - ret.setRect(xposMod, ypos + buttonMargin, buttonWidth, height - 2 * buttonMargin); + ret.setRect(xposMod, ypos + buttonMargin, buttonSize.width(), height - 2 * buttonMargin); } break; case SC_ComboBoxEditField: { - const int withFrameX = cmb->rect.x() + width - frameThickness - buttonSize.width(); - ret = QRect( - frameThickness, - frameThickness, - withFrameX - frameThickness, - height - 2 * frameThickness); + ret = QRect(0, 0, cmb->rect.x() + width - buttonSize.width(), height); } break; case SC_ComboBoxListBoxPopup: { diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index ced0d73f..36e9ef7 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -399,7 +399,7 @@ void QComboBoxPrivateContainer::leaveEvent(QEvent *) #ifdef Q_WS_MAC QStyleOptionComboBox opt = comboStyleOption(); if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) - view->clearSelection(); + view->setCurrentIndex(QModelIndex()); #endif } |