本文整理汇总了C++中QSize::boundedTo方法的典型用法代码示例。如果您正苦于以下问题:C++ QSize::boundedTo方法的具体用法?C++ QSize::boundedTo怎么用?C++ QSize::boundedTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSize
的用法示例。
在下文中一共展示了QSize::boundedTo方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: preferredSizeHint
QSize KexiView::preferredSizeHint(const QSize& otherSize)
{
#ifdef __GNUC__
#warning KexiView::preferredSizeHint()
#else
#pragma WARNING( KexiView::preferredSizeHint() )
#endif
#if 0 //todo
KexiWindow* w = d->window;
if (dlg && dlg->mdiParent()) {
QRect r = dlg->mdiParent()->mdiAreaContentsRect();
return otherSize.boundedTo(QSize(
r.width() - 10,
r.height() - dlg->mdiParent()->captionHeight() - dlg->pos().y() - 10
));
}
#endif
return otherSize;
}
示例2: sizeHint
QSize PropertyEditorDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
const QVariant value = index.data(Qt::EditRole);
if (value.canConvert<QMatrix4x4>()) {
return sizeHint(option, index, value.value<QMatrix4x4>());
} else if (value.canConvert<QMatrix>()) {
return sizeHint(option, index, value.value<QMatrix>());
} else if (value.type() == QVariant::Transform) {
return sizeHint(option, index, value.value<QTransform>());
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
} else if (value.canConvert<QVector2D>()) {
return sizeHint(option, index, value.value<QVector2D>());
} else if (value.canConvert<QVector3D>()) {
return sizeHint(option, index, value.value<QVector3D>());
} else if (value.canConvert<QVector4D>()) {
return sizeHint(option, index, value.value<QVector4D>());
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
} else if (value.type() == QVariant::Quaternion) {
return sizeHint(option, index, value.value<QQuaternion>());
#endif
}
// We don't want multiline texts for String values
if (value.type() == QVariant::String) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QStyleOptionViewItem opt = option;
#else
QStyleOptionViewItemV4 opt = *qstyleoption_cast<const QStyleOptionViewItemV4 *>(&option);
#endif
if (opt.text.isEmpty() && !placeholderText().isEmpty())
opt.text = defaultDisplayText(index);
QSize sh = QStyledItemDelegate::sizeHint(opt, index);
initStyleOption(&opt, index);
return sh.boundedTo(QSize(sh.width(), opt.fontMetrics.height()));
}
return QStyledItemDelegate::sizeHint(option, index);
}
示例3: getDefaultGeometry
QRect DlgPreferences::getDefaultGeometry() {
QSize optimumSize;
adjustSize();
optimumSize = qApp->desktop()->availableGeometry(this).size();
if (frameSize() == size()) {
// This code is reached in Gnome 2.3
qDebug() << "guess the size of the window decoration";
optimumSize -= QSize(2,30);
} else {
optimumSize -= (frameSize() - size());
}
QSize staticSize = size() - pagesWidget->size();
optimumSize = optimumSize.boundedTo(staticSize + m_pageSizeHint);
QRect optimumRect = geometry();
optimumRect.setSize(optimumSize);
return optimumRect;
}
示例4: openBlankDocument
void DrawpileApp::openBlankDocument()
{
// Open a new window with a blank image
QSettings cfg;
QSize maxSize = desktop()->screenGeometry().size();
QSize size = cfg.value("history/newsize").toSize();
if(size.width()<100 || size.height()<100) {
// No previous size, or really small size
size = QSize(800, 600);
} else {
// Make sure previous size is not ridiculously huge
size = size.boundedTo(maxSize);
}
QColor color = cfg.value("history/newcolor").value<QColor>();
if(!color.isValid())
color = Qt::white;
MainWindow *win = new MainWindow;
win->newDocument(size, color);
}
示例5: draw
/*!
\brief Draw the spectrogram
\param painter Painter
\param xMap Maps x-values into pixel coordinates.
\param yMap Maps y-values into pixel coordinates.
\param canvasRect Contents rectangle of the canvas in painter coordinates
\sa setDisplayMode(), renderImage(),
QwtPlotRasterItem::draw(), drawContourLines()
*/
void QwtPlotSpectrogram::draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect ) const
{
if ( d_data->displayMode & ImageMode )
QwtPlotRasterItem::draw( painter, xMap, yMap, canvasRect );
if ( d_data->displayMode & ContourMode )
{
// Add some pixels at the borders
const int margin = 2;
QRectF rasterRect( canvasRect.x() - margin, canvasRect.y() - margin,
canvasRect.width() + 2 * margin, canvasRect.height() + 2 * margin );
QRectF area = QwtScaleMap::invTransform( xMap, yMap, rasterRect );
const QRectF br = boundingRect();
if ( br.isValid() )
{
area &= br;
if ( area.isEmpty() )
return;
rasterRect = QwtScaleMap::transform( xMap, yMap, area );
}
QSize raster = contourRasterSize( area, rasterRect.toRect() );
raster = raster.boundedTo( rasterRect.toRect().size() );
if ( raster.isValid() )
{
const QwtRasterData::ContourLines lines =
renderContourLines( area, raster );
drawContourLines( painter, xMap, yMap, lines );
}
}
}
示例6: ItemViewSizeHint
static QSize ItemViewSizeHint(const QWidget * us, const ViewWidget * view)
{
// maximum size - half screen
QSize maxSize = QApplication::desktop()->screenGeometry().size();
maxSize /= 2;
// but no more than maximumSize()
maxSize = maxSize.boundedTo(us->maximumSize());
// if we are in QMdiArea, then our sizeHint should not be more than one third of QMdiArea size
if (auto mdi = QtTools::FindAncestor<QMdiArea>(us))
{
maxSize = mdi->size();
maxSize /= 3;
}
// additional size - size of all layout'а
// minus size of tableView, size of which we calculate ourself.
// QTableView::sizeHint in fact always return dummy size: 256:192
QSize addSz = us->QWidget::sizeHint() - view->sizeHint();
maxSize -= addSz;
auto sz = QtTools::ItemViewSizeHint(view, view->minimumSizeHint(), maxSize);
return sz += addSz;
}
示例7: sizeFromContent
QSize QDockWidgetLayout::sizeFromContent(const QSize &content, bool floating) const
{
QSize result = content;
if (verticalTitleBar) {
result.setHeight(qMax(result.height(), minimumTitleWidth()));
result.setWidth(qMax(content.width(), 0));
} else {
result.setHeight(qMax(result.height(), 0));
result.setWidth(qMax(content.width(), minimumTitleWidth()));
}
QDockWidget *w = qobject_cast<QDockWidget*>(parentWidget());
const bool nativeDeco = nativeWindowDeco(floating);
int fw = floating && !nativeDeco
? w->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, w)
: 0;
const int th = titleHeight();
if (!nativeDeco) {
if (verticalTitleBar)
result += QSize(th + 2*fw, 2*fw);
else
result += QSize(2*fw, th + 2*fw);
}
result.setHeight(qMin(result.height(), (int) QWIDGETSIZE_MAX));
result.setWidth(qMin(result.width(), (int) QWIDGETSIZE_MAX));
if (content.width() < 0)
result.setWidth(-1);
if (content.height() < 0)
result.setHeight(-1);
int left, top, right, bottom;
w->getContentsMargins(&left, &top, &right, &bottom);
//we need to substract the contents margin (it will be added by the caller)
QSize min = w->minimumSize() - QSize(left + right, top + bottom);
QSize max = w->maximumSize() - QSize(left + right, top + bottom);
/* A floating dockwidget will automatically get its minimumSize set to the layout's
minimum size + deco. We're *not* interested in this, we only take minimumSize()
into account if the user set it herself. Otherwise we end up expanding the result
of a calculation for a non-floating dock widget to a floating dock widget's
minimum size + window decorations. */
uint explicitMin = 0;
uint explicitMax = 0;
if (w->d_func()->extra != 0) {
explicitMin = w->d_func()->extra->explicitMinSize;
explicitMax = w->d_func()->extra->explicitMaxSize;
}
if (!(explicitMin & Qt::Horizontal) || min.width() == 0)
min.setWidth(-1);
if (!(explicitMin & Qt::Vertical) || min.height() == 0)
min.setHeight(-1);
if (!(explicitMax & Qt::Horizontal))
max.setWidth(QWIDGETSIZE_MAX);
if (!(explicitMax & Qt::Vertical))
max.setHeight(QWIDGETSIZE_MAX);
return result.boundedTo(max).expandedTo(min);
}
示例8: main
int main(int argc, char *argv[]) {
// Initialize application
DrawpileApp app(argc,argv);
icon::selectThemeVariant();
#ifdef Q_OS_MAC
// Mac specific settings
app.setAttribute(Qt::AA_DontShowIconsInMenus);
app.setQuitOnLastWindowClosed(false);
// Global menu bar that is shown when no windows are open
MacMenu::instance();
#endif
qsrand(QDateTime::currentMSecsSinceEpoch());
Color_Wheel::setDefaultDisplayFlags(Color_Wheel::SHAPE_SQUARE | Color_Wheel::ANGLE_FIXED | Color_Wheel::COLOR_HSV);
{
// Set override locale from settings, or use system locale if no override is set
QLocale locale = QLocale::c();
QString overrideLang = QSettings().value("settings/language").toString();
if(!overrideLang.isEmpty())
locale = QLocale(overrideLang);
if(locale == QLocale::c())
locale = QLocale::system();
initTranslations(locale);
}
const QStringList args = app.arguments();
if(args.count()>1) {
QUrl url(args.at(1));
if(url.scheme().length() <= 1) {
// no scheme (or a drive letter?) means this is probably a local file
url = QUrl::fromLocalFile(args.at(1));
}
app.openUrl(url);
} else {
// No arguments, start with an empty document
QSettings cfg;
QSize maxSize = app.desktop()->screenGeometry().size();
QSize size = cfg.value("history/newsize").toSize();
if(size.width()<100 || size.height()<100) {
// No previous size, or really small size
size = QSize(800, 600);
} else {
// Make sure previous size is not ridiculously huge
size = size.boundedTo(maxSize);
}
QColor color = cfg.value("history/newcolor").value<QColor>();
if(!color.isValid())
color = Qt::white;
MainWindow *win = new MainWindow;
win->newDocument(size, color);
}
return app.exec();
}
示例9: tabSizeHint
QSize TabBar::tabSizeHint(int index) const
{
QSize sizeHint = QTabBar::tabSizeHint(index);
QFontMetrics fm = fontMetrics();
return sizeHint.boundedTo(QSize(fm.width(QLatin1Char('M')) * 18, sizeHint.height()));
}
示例10: alignGeometry
QRect WidgetManager::alignGeometry(const QSize &ASize, const QWidget *AWidget, Qt::Alignment AAlign)
{
QRect availRect = AWidget!=NULL ? QApplication::desktop()->availableGeometry(AWidget) : QApplication::desktop()->availableGeometry();
return QStyle::alignedRect(Qt::LeftToRight,AAlign,ASize.boundedTo(availRect.size()),availRect);
}
示例11: find
void FindBar::find(FindBar::FindDirection dir)
{
Q_ASSERT(m_associatedWebView);
if (isHidden()) {
QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition();
m_associatedWebView->page()->focusNextPrevChild(true);
m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position);
return;
}
QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
if (dir == Backward)
options |= QWebPage::FindBackward;
if (matchCase())
options |= QWebPage::FindCaseSensitively;
// HACK Because we're using the QWebView inside a QScrollArea container, the attempts
// to scroll the QWebView itself have no direct effect.
// Therefore we temporarily shrink the page viewport to the message viewport (ie. the size it
// can cover at max), then perform the search, store the scrollPosition, restore the page viewport
// and finally scroll the messageview to the gathered scrollPosition, mapped to the message (ie.
// usually offset by the mail header)
auto emb = qobject_cast<EmbeddedWebView *>(m_associatedWebView);
QAbstractScrollArea *container = emb ? static_cast<QAbstractScrollArea*>(emb->scrollParent()) : nullptr;
const QSize oldVpS = m_associatedWebView->page()->viewportSize();
const bool useResizeTrick = container ? !!container->verticalScrollBar() : false;
// first shrink the page viewport
if (useResizeTrick) {
m_associatedWebView->setUpdatesEnabled(false); // don't let the user see the flicker we might produce
QSize newVpS = oldVpS.boundedTo(container->size());
m_associatedWebView->page()->setViewportSize(newVpS);
}
// now perform the search (pot. in the shrinked viewport)
bool found = m_associatedWebView->page()->findText(_lastStringSearched, options);
notifyMatch(found);
// scroll and reset the page viewport if necessary
if (useResizeTrick) {
Q_ASSERT(container->verticalScrollBar());
// the page has now a usable scroll position ...
int scrollPosition = m_associatedWebView->page()->currentFrame()->scrollPosition().y();
// ... which needs to be extended by the pages offset (usually the header widget)
// NOTICE: QWidget::mapTo() fails as the viewport child position can be negative, so we run ourself
QWidget *runner = m_associatedWebView;
while (runner->parentWidget() != container->viewport()) {
scrollPosition += runner->y();
runner = runner->parentWidget();
}
// reset viewport to original size ...
m_associatedWebView->page()->setViewportSize(oldVpS);
// ... let the user see the change ...
m_associatedWebView->setUpdatesEnabled(true);
// ... and finally scroll to the desired position
if (found)
container->verticalScrollBar()->setValue(scrollPosition);
}
if (!found) {
QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition();
m_associatedWebView->page()->focusNextPrevChild(true);
m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position);
}
}