Example #1
0
void LineEdit::init()
{
    m_leftWidget = new SideWidget(this);
    m_leftWidget->resize(0, 0);
    m_leftLayout = new QHBoxLayout(m_leftWidget);
    m_leftLayout->setContentsMargins(0, 0, 0, 0);
    if (isRightToLeft())
        m_leftLayout->setDirection(QBoxLayout::RightToLeft);
    else
        m_leftLayout->setDirection(QBoxLayout::LeftToRight);
    m_leftLayout->setSizeConstraint(QLayout::SetFixedSize);

    m_rightWidget = new SideWidget(this);
    m_rightWidget->resize(0, 0);
    m_rightLayout = new QHBoxLayout(m_rightWidget);
    if (isRightToLeft())
        m_rightLayout->setDirection(QBoxLayout::RightToLeft);
    else
        m_rightLayout->setDirection(QBoxLayout::LeftToRight);
    m_rightLayout->setContentsMargins(0, 0, 0, 0);

    QSpacerItem *horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
    m_rightLayout->addItem(horizontalSpacer);

    setWidgetSpacing(3);
    connect(m_leftWidget, SIGNAL(sizeHintChanged()),
            this, SLOT(updateTextMargins()));
    connect(m_rightWidget, SIGNAL(sizeHintChanged()),
            this, SLOT(updateTextMargins()));
}
Example #2
0
void VolumeSlider::paintEvent(QPaintEvent *)
{
    bool reverse=isRightToLeft();
    QPainter p(this);
    bool muted=MPDConnection::self()->isMuted();
    if (muted || !isEnabled()) {
        p.setOpacity(0.25);
    }

    p.drawPixmap(0, 0, pixmaps[0]);
#if 1
    int steps=(value()/10.0)+0.5;
    if (steps>0) {
        if (steps<10) {
            int wStep=widthStep*lineWidth;
            p.setClipRect(reverse
                          ? QRect(width()-((steps*wStep*2)-wStep), 0, width(), height())
                          : QRect(0, 0, (steps*wStep*2)-wStep, height()));
            p.setClipping(true);
        }
        p.drawPixmap(0, 0, pixmaps[1]);
        if (steps<10) {
            p.setClipping(false);
        }
    }
#else // Partial filling of each block?
    if (value()>0) {
        if (value()<100) {
            int fillWidth=(width()*(0.01*value()))+0.5;
            p.setClipRect(reverse
                          ? QRect(width()-fillWidth, 0, width(), height())
                          : QRect(0, 0, fillWidth, height()));
            p.setClipping(true);
        }
        p.drawPixmap(0, 0, *(pixmaps[1]));
        if (value()<100) {
            p.setClipping(false);
        }
    }
#endif

    if (!muted) {
        p.setOpacity(p.opacity()*0.75);
        p.setPen(textCol);
        QFont f(font());
        f.setPixelSize(qMax(height()/2.5, 8.0));
        p.setFont(f);
        QRect r=rect();
        bool rtl=isRightToLeft();
        if (rtl) {
            r.setX(widthStep*lineWidth*12);
        } else {
            r.setWidth(widthStep*lineWidth*7);
        }
        p.drawText(r, Qt::AlignRight, QString("%1%").arg(value()));
    }
}
Example #3
0
bool Formula::isInSameDirection(Node startRoad, Node endRoad, Node startClick, Node endClick)
{
    if ((isLeftToRight(startRoad, endRoad) && isLeftToRight(startClick, endClick)) ||
        (isTopToBottom(startRoad, endRoad) && isTopToBottom(startClick, endClick)) ||
        (isRightToLeft(startRoad, endRoad) && isRightToLeft(startClick, endClick)) ||
        (isBottomToTop(startRoad, endRoad) && isBottomToTop(startClick, endClick)))
        return true;
    return false;
}
Example #4
0
void TabBar::mouseMoveEvent(QMouseEvent* ev)
{
    if (d->readOnly) return;

    QPoint pos = ev->pos();
    if (!isRightToLeft()) pos = pos - QPoint(d->offset, 0);

    // check if user drags a tab to move it
    int i = d->tabAt(pos) + 1;
    if ((i > 0) && (i != d->targetTab)) {
        if (i == d->activeTab) i = 0;
        if (i == d->activeTab + 1) i = 0;

        if (i != d->targetTab) {
            d->targetTab = i;
            d->autoScroll = false;
            update();
        }
    }

    // drag past the very latest visible tab
    // e.g move a tab to the last ordering position
    QRect r = d->tabRects[ d->tabRects.count()-1 ];
    bool moveToLast = false;
    if (r.isValid()) {
        if (!isRightToLeft())
            if (pos.x() > r.right())
                if (pos.x() < width())
                    moveToLast = true;
        if (isRightToLeft())
            if (pos.x() < r.x())
                if (pos.x() > 0)
                    moveToLast = true;
    }
    if (moveToLast)
        if (d->targetTab != (int)d->tabRects.count() + 1) {
            d->targetTab = d->tabRects.count() + 1;
            d->autoScroll = false;
            update();
        }

    // outside far too left ? activate autoscroll...
    if (pos.x() < 0 && !d->autoScroll) {
        d->autoScroll = true;
        autoScrollBack();
    }

    // outside far too right ? activate autoscroll...
    int w = width() - d->offset;
    if (pos.x() > w && !d->autoScroll) {
        d->autoScroll = true;
        autoScrollForward();
    }
}
Example #5
0
/*!
    \reimp
 */
void QxtStars::paintEvent(QPaintEvent* event)
{
    QAbstractSlider::paintEvent(event);

    QPainter painter(this);
    painter.save();
    painter.setPen(palette().color(QPalette::Text));
    painter.setRenderHint(QPainter::Antialiasing);

    const bool invert = invertedAppearance();
    const QSize size = qxt_d().getStarSize();
    const QRectF star = qxt_d().star.boundingRect();
    painter.scale(size.width() / star.width(), size.height() / star.height());
    const int count = maximum() - minimum();
    if (orientation() == Qt::Horizontal)
    {
        painter.translate(-star.x(), -star.y());
        if (invert != isRightToLeft())
            painter.translate((count - 1) * star.width(), 0);
    }
    else
    {
        painter.translate(-star.x(), -star.y());
        if (!invert)
            painter.translate(0, (count - 1) * star.height());
    }
    for (int i = 0; i < count; ++i)
    {
        if (value() > minimum() + i)
            painter.setBrush(palette().highlight());
        else
            painter.setBrush(palette().base());
        painter.drawPath(qxt_d().star);

        if (orientation() == Qt::Horizontal)
            painter.translate(invert != isRightToLeft() ? -star.width() : star.width(), 0);
        else
            painter.translate(0, invert ? star.height() : -star.height());
    }

    painter.restore();
    if (hasFocus())
    {
        QStyleOptionFocusRect opt;
        opt.initFrom(this);
        opt.rect.setSize(sizeHint());
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &painter, this);
    }
}
Example #6
0
void TabBar::scrollLast()
{
    if (!canScrollForward())
        return;

    d->layoutTabs();

    if (!isRightToLeft()) {
        int fullWidth = d->tabRects[ d->tabRects.count()-1 ].right();
        int delta = fullWidth - width() + d->offset;
        for (int i = 0; i < d->tabRects.count(); i++)
            if (d->tabRects[i].x() > delta) {
                d->firstTab = i + 1;
                break;
            }
    } else {
        // FIXME optimize this, perhaps without loop
        for (; d->firstTab <= (int)d->tabRects.count();) {
            int x = d->tabRects[ d->tabRects.count()-1 ].x();
            if (x > 0) break;
            d->firstTab++;
            d->layoutTabs();
        }
    }

    d->layoutTabs();
    d->updateButtons();
    update();
}
Example #7
0
void TabBar::mouseDoubleClickEvent(QMouseEvent* ev)
{
    int offset = isRightToLeft() ? 0 : d->offset;
    if (ev->pos().x() > offset)
        if (!d->readOnly)
            emit doubleClicked();
}
void HierarchicalHeaderView::on_sectionResized(int logicalIndex)
{
	if(isSectionHidden(logicalIndex))
		return;

	QModelIndex leafIndex(_pd->leafIndex(logicalIndex));
	if(leafIndex.isValid())
	{
		QModelIndexList leafsList(_pd->leafs(_pd->findRootIndex(leafIndex)));
		for(int n=leafsList.indexOf(leafIndex); n>0; --n)
		{
			--logicalIndex;

			int w = viewport()->width();
			int h = viewport()->height();
			int pos = sectionViewportPosition(logicalIndex);
			QRect r(pos, 0, w - pos, h);
			if(orientation() == Qt::Horizontal)
			{
				if (isRightToLeft())
					r.setRect(0, 0, pos + sectionSize(logicalIndex), h);
			}
			else
				r.setRect(0, pos, w, h - pos);

			viewport()->update(r.normalized());
		}
	}
}
Example #9
0
void GraphicsDImgView::scrollPointOnPoint(const QPointF& scenePos, const QPoint& viewportPos)
{
    // This is inspired from QGraphicsView's centerOn()
    QPointF viewPoint = matrix().map(scenePos);

    if (horizontalScrollBar()->maximum())
    {
        if (isRightToLeft())
        {
            qint64 horizontal = 0;
            horizontal += horizontalScrollBar()->minimum();
            horizontal += horizontalScrollBar()->maximum();
            horizontal -= int(viewPoint.x() - viewportPos.x());
            horizontalScrollBar()->setValue(horizontal);
        }
        else
        {
            horizontalScrollBar()->setValue(int(viewPoint.x() - viewportPos.x()));
        }
    }

    if (verticalScrollBar()->maximum())
    {
        verticalScrollBar()->setValue(int(viewPoint.y() - viewportPos.y()));
    }

    viewport()->update();
}
Example #10
0
bool MenuButton::eventFilter(QObject *o, QEvent *e)
{
    if (QEvent::Show==e->type()) {
        if (qobject_cast<QMenu *>(o)) {
            QMenu *mnu=static_cast<QMenu *>(o);
            QPoint p=parentWidget()->mapToGlobal(pos());
            int newPos=isRightToLeft()
                    ? p.x()
                    : ((p.x()+width())-mnu->width());

            if (newPos<0) {
                newPos=0;
            } else {
                QDesktopWidget *dw=QApplication::desktop();
                if (dw) {
                    QRect geo=dw->availableGeometry(this);
                    int maxWidth=geo.x()+geo.width();
                    if (maxWidth>0 && (newPos+mnu->width())>maxWidth) {
                        newPos=maxWidth-mnu->width();
                    }
                }
            }
            mnu->move(newPos, mnu->y());
        } else if (o==this) {
            setMinimumWidth(height());
            removeEventFilter(this);
        }
    }

    return ToolButton::eventFilter(o, e);
}
Example #11
0
    void paintEvent(QPaintEvent *ev)
    {
        Q_UNUSED(ev)
        QPainter painter(this);
        QString txt=text();
        bool mo=underMouse();

        txt.replace("&", "");
        QFont f(font());
        if (isChecked()) {
            f.setBold(true);
        }
        QFontMetrics fm(f);
        if (fm.width(txt)>rect().width()) {
            txt=fm.elidedText(txt, isRightToLeft() ? Qt::ElideLeft : Qt::ElideRight, rect().width());
        }

        painter.setFont(f);
        if (isChecked() || mo) {
            int lh=Utils::isHighDpi() ? 5 : 3;
            #ifdef Q_OS_MAC
            QColor col=OSXStyle::self()->viewPalette().highlight().color();
            #else
            QColor col=palette().color(QPalette::Highlight);
            #endif
            if (mo) {
                col.setAlphaF(isChecked() ? 0.75 : 0.5);
            }
            QRect r=rect();
            painter.fillRect(r.x(), r.y()+r.height()-(lh+1), r.width(), lh, col);
        }
        painter.setPen(palette().color(QPalette::Text));
        painter.drawText(rect(), Qt::AlignCenter, txt);
    }
Example #12
0
void TabBar::mousePressEvent(QMouseEvent* ev)
{
    if (d->tabs.count() == 0) {
        update();
        return;
    }

    d->layoutTabs();

    QPoint pos = ev->pos();
    if (!isRightToLeft()) pos = pos - QPoint(d->offset, 0);

    int tab = d->tabAt(pos) + 1;
    if ((tab > 0) && (tab != d->activeTab)) {
        d->activeTab = tab;
        update();

        emit tabChanged(d->tabs[ d->activeTab-1]);

        // scroll if partially visible
        if (d->tabRects[ tab-1 ].right() > width() - d->offset)
            scrollForward();
    }

    if (ev->button() == Qt::RightButton)
        if (!d->readOnly)
            emit contextMenu(ev->globalPos());
}
Example #13
0
void GraphicsDImgView::continuePanning(const QPoint& pos)
{
    QPoint delta = pos - d->mousePressPos;
    horizontalScrollBar()->setValue(d->panningScrollPos.x() + (isRightToLeft() ? delta.x() : -delta.x()));
    verticalScrollBar()->setValue(d->panningScrollPos.y() - delta.y());
    emit contentsMoved(false);
    viewport()->update();
}
Example #14
0
void TabBar::paintEvent(QPaintEvent*)
{
    if (d->tabs.count() == 0) {
        update();
        return;
    }

    d->layoutTabs();
    d->updateButtons();

    QPainter painter(this);
    if (!isRightToLeft())
        painter.translate(d->offset, 0);

    if (!isRightToLeft())
        painter.translate(5, 0);

    // draw first all non-active, visible tabs
    for (int c = d->tabRects.count() - 1; c >= 0; c--) {
        QRect rect = d->tabRects[ c ];
        if (rect.isNull()) continue;
        QString text = d->tabs[ c ];
        d->drawTab(painter, rect, text, false);
    }

    // draw the active tab
    if (d->activeTab > 0) {
        QRect rect = d->tabRects[ d->activeTab-1 ];
        if (!rect.isNull()) {
            QString text = d->tabs[ d->activeTab-1 ];
            d->drawTab(painter, rect, text, true);
        }
    }

    // draw the move marker
    if (d->targetTab > 0) {
        int p = qMin(d->targetTab, (int)d->tabRects.count());
        QRect rect = d->tabRects[ p-1 ];
        if (!rect.isNull()) {
            int x = !isRightToLeft() ? rect.x() : rect.right() - 7;
            if (d->targetTab > (int)d->tabRects.count())
                x = !isRightToLeft() ? rect.right() - 7 : rect.x() - 3;
            d->drawMoveMarker(painter, x, rect.y());
        }
    }
}
Example #15
0
CookieManager::CookieManager(QWidget* parent)
    : QDialog(parent)
    , ui(new Ui::CookieManager)
    , m_refreshCookieJar(true)
{
    ui->setupUi(this);
    QzTools::centerWidgetOnScreen(this);

    if (isRightToLeft()) {
        ui->cookieTree->headerItem()->setTextAlignment(0, Qt::AlignRight | Qt::AlignVCenter);
        ui->cookieTree->headerItem()->setTextAlignment(1, Qt::AlignRight | Qt::AlignVCenter);
        ui->cookieTree->setLayoutDirection(Qt::LeftToRight);
        ui->whiteList->setLayoutDirection(Qt::LeftToRight);
        ui->blackList->setLayoutDirection(Qt::LeftToRight);
    }

    // Stored Cookies
    connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
    connect(ui->removeAll, SIGNAL(clicked()), this, SLOT(removeAll()));
    connect(ui->removeOne, SIGNAL(clicked()), this, SLOT(removeCookie()));
    connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
    connect(ui->close2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
    connect(ui->close3, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
    connect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));

    // Cookie Filtering
    connect(ui->whiteAdd, SIGNAL(clicked()), this, SLOT(addWhitelist()));
    connect(ui->whiteRemove, SIGNAL(clicked()), this, SLOT(removeWhitelist()));
    connect(ui->blackAdd, SIGNAL(clicked()), this, SLOT(addBlacklist()));
    connect(ui->blackRemove, SIGNAL(clicked()), this, SLOT(removeBlacklist()));

    // Cookie Settings
    Settings settings;
    settings.beginGroup("Cookie-Settings");
    ui->saveCookies->setChecked(settings.value("allowCookies", true).toBool());
    if (!ui->saveCookies->isChecked()) {
        ui->deleteCookiesOnClose->setEnabled(false);
    }
    ui->deleteCookiesOnClose->setChecked(settings.value("deleteCookiesOnClose", false).toBool());
    ui->allowThirdPartyCookies->setCurrentIndex(settings.value("allowThirdPartyCookies", 0).toInt());
    ui->filterTracking->setChecked(settings.value("filterTrackingCookie", false).toBool());
    settings.endGroup();

    connect(ui->saveCookies, SIGNAL(toggled(bool)), this, SLOT(saveCookiesChanged(bool)));

    ui->search->setPlaceholderText(tr("Search"));
    ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
    ui->cookieTree->sortItems(0, Qt::AscendingOrder);
    ui->cookieTree->header()->setDefaultSectionSize(220);
    ui->cookieTree->setFocus();

    QShortcut* removeShortcut = new QShortcut(QKeySequence("Del"), this);
    connect(removeShortcut, SIGNAL(activated()), this, SLOT(deletePressed()));

    QzTools::setWmClass("Cookies", this);

    refreshTable();
}
Example #16
0
void QExpandingLineEdit::resizeToContents()
{
    int oldWidth = width();
    if (originalWidth == -1)
        originalWidth = oldWidth;
    if (QWidget *parent = parentWidget()) {
        QPoint position = pos();
        int hintWidth = minimumWidth() + fontMetrics().width(displayText());
        int parentWidth = parent->width();
        int maxWidth = isRightToLeft() ? position.x() + oldWidth : parentWidth - position.x();
        int newWidth = qBound(originalWidth, hintWidth, maxWidth);
        if (widgetOwnsGeometry)
            setMaximumWidth(newWidth);
        if (isRightToLeft())
            move(position.x() - newWidth + oldWidth, position.y());
        resize(newWidth, height());
    }
}
Example #17
0
/*!
    \reimp
    Resize the parent window to the sizeHint
*/
void QColumnViewGrip::mouseDoubleClickEvent(QMouseEvent *event)
{
    Q_UNUSED(event);
    QWidget *parentWidget = (QWidget*)parent();
    int offset = parentWidget->sizeHint().width() - parentWidget->width();
    if (isRightToLeft())
        offset *= -1;
    moveGrip(offset);
    event->accept();
}
Example #18
0
FCM_Dialog::FCM_Dialog(FCM_Plugin* manager, QWidget* parent)
    : QDialog(parent, Qt::WindowStaysOnTopHint)
    , ui(new Ui::FCM_Dialog)
    , m_manager(manager)
{
    ui->setupUi(this);
    QzTools::centerWidgetOnScreen(this);

    ui->path->hide();
    ui->labelPath->hide();

    if (isRightToLeft()) {
        ui->flashCookieTree->headerItem()->setTextAlignment(0, Qt::AlignRight | Qt::AlignVCenter);
        ui->flashCookieTree->setLayoutDirection(Qt::LeftToRight);
        ui->whiteList->setLayoutDirection(Qt::LeftToRight);
        ui->blackList->setLayoutDirection(Qt::LeftToRight);
    }

    connect(ui->flashCookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
    connect(ui->removeAll, SIGNAL(clicked()), this, SLOT(removeAll()));
    connect(ui->removeOne, SIGNAL(clicked()), this, SLOT(removeCookie()));
    connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
    connect(ui->close2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
    connect(ui->close3, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
    connect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
    connect(ui->reloadFromDisk, SIGNAL(clicked()), this, SLOT(reloadFromDisk()));

    connect(ui->whiteAdd, SIGNAL(clicked()), this, SLOT(addWhitelist()));
    connect(ui->whiteRemove, SIGNAL(clicked()), this, SLOT(removeWhitelist()));
    connect(ui->blackAdd, SIGNAL(clicked()), this, SLOT(addBlacklist()));
    connect(ui->blackRemove, SIGNAL(clicked()), this, SLOT(removeBlacklist()));

    connect(ui->autoMode, SIGNAL(toggled(bool)), ui->notification, SLOT(setEnabled(bool)));
    connect(ui->autoMode, SIGNAL(toggled(bool)), ui->labelNotification, SLOT(setEnabled(bool)));
    connect(ui->browseFlashDataPath, SIGNAL(clicked()), this, SLOT(selectFlashDataPath()));

    ui->autoMode->setChecked(m_manager->readSettings().value("autoMode").toBool());
    ui->notification->setEnabled(m_manager->readSettings().value("autoMode").toBool());
    ui->notification->setChecked(m_manager->readSettings().value("notification").toBool());
    ui->deleteAllOnStartExit->setChecked(m_manager->readSettings().value("deleteAllOnStartExit").toBool());
    ui->flashDataPath->setText(m_manager->flashPlayerDataPath());

    ui->labelNotification->setEnabled(ui->autoMode->isChecked());

    ui->search->setPlaceholderText(tr("Search"));
    ui->flashCookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
    ui->flashCookieTree->sortItems(0, Qt::AscendingOrder);
    ui->flashCookieTree->header()->setDefaultSectionSize(220);
    ui->flashCookieTree->setFocus();

    QShortcut* removeShortcut = new QShortcut(QKeySequence("Del"), this);
    connect(removeShortcut, SIGNAL(activated()), this, SLOT(deletePressed()));

    QzTools::setWmClass("FlashCookies", this);
}
Example #19
0
void LineEdit::resizeEvent(QResizeEvent *e)
{
    QSize sz = clearButton->sizeHint();
    int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    if (isRightToLeft()) {
        clearButton->move(rect().left() + frameWidth, (rect().bottom() + 1 - sz.height()) / 2);
    } else {
        clearButton->move(rect().right() - frameWidth - sz.width(), (rect().bottom() + 1 - sz.height()) / 2);
    }
    QLineEdit::resizeEvent(e);
}
Example #20
0
void TabBar::moveAddTabButton(int posX)
{
    int posY = (height() - m_addTabButton->height()) / 2;

    if (isRightToLeft()) {
        posX = qMax(posX - m_addTabButton->width(), 0);
    }
    else {
        posX = qMin(posX, width() - m_addTabButton->width());
    }
    m_addTabButton->move(posX, posY);
}
Example #21
0
bool LineEdit::event(QEvent *event)
{
    if (event->type() == QEvent::LayoutDirectionChange) {
        if (isRightToLeft()) {
            m_leftLayout->setDirection(QBoxLayout::RightToLeft);
            m_rightLayout->setDirection(QBoxLayout::RightToLeft);
        } else {
            m_leftLayout->setDirection(QBoxLayout::LeftToRight);
            m_rightLayout->setDirection(QBoxLayout::LeftToRight);
        }
    }
    return QLineEdit::event(event);
}
Example #22
0
void LineEdit::addWidget(QWidget *widget, WidgetPosition position)
{
    if (!widget)
        return;

    bool rtl = isRightToLeft();
    if (rtl)
        position = (position == LeftSide) ? RightSide : LeftSide;
    if (position == LeftSide) {
        m_leftLayout->addWidget(widget);
    } else {
        m_rightLayout->insertWidget(1, widget);
    }
}
Example #23
0
void QIMainDialog::resizeEvent(QResizeEvent *pEvent)
{
    /* Call to base-class: */
    QMainWindow::resizeEvent(pEvent);

    /* Adjust the size-grip location for the current resize event: */
    if (m_pSizeGrip)
    {
        if (isRightToLeft())
            m_pSizeGrip->move(rect().bottomLeft() - m_pSizeGrip->rect().bottomLeft());
        else
            m_pSizeGrip->move(rect().bottomRight() - m_pSizeGrip->rect().bottomRight());
    }
}
Example #24
0
/*!
    Attempt to resize the parent object by \a offset
    returns the amount of offset that it was actually able to resized
*/
int QColumnViewGrip::moveGrip(int offset)
{
    QWidget *parentWidget = (QWidget*)parent();

    // first resize the parent
    int oldWidth = parentWidget->width();
    int newWidth = oldWidth;
    if (isRightToLeft())
        newWidth -= offset;
    else
        newWidth += offset;
    newWidth = qMax(parentWidget->minimumWidth(), newWidth);
    parentWidget->resize(newWidth, parentWidget->height());

    // Then have the view move the widget
    int realOffset = parentWidget->width() - oldWidth;
    int oldX = parentWidget->x();
    if (realOffset != 0)
        emit gripMoved(realOffset);
    if (isRightToLeft())
        realOffset = -1 * (oldX - parentWidget->x());
    return realOffset;
}
Example #25
0
void ColorWidget::mouseReleaseEvent(QMouseEvent *event)
{
	QWidget::mouseReleaseEvent(event);

	if (event->button() == Qt::LeftButton && m_buttonRectangle.contains(event->pos()))
	{
		QMenu menu(this);
		menu.addAction(tr("Select Color…"), this, SLOT(selectColor()));
		menu.addAction(tr("Copy Color"), this, SLOT(copyColor()));
		menu.addSeparator();
		menu.addAction(ThemesManager::createIcon(QLatin1String("edit-clear")), tr("Clear"), this, SLOT(clear()));
		menu.exec(mapToGlobal(isRightToLeft() ? m_buttonRectangle.bottomRight() : m_buttonRectangle.bottomLeft()));
	}
}
Example #26
0
void SCgView::mouseMoveEvent (QMouseEvent * event)
{
    if(event->buttons() & Qt::MidButton)
    {
        viewport()->setCursor(Qt::ClosedHandCursor);
        QScrollBar *hBar = horizontalScrollBar();
        QScrollBar *vBar = verticalScrollBar();
        QPoint delta = event->pos() - mPrevMousePos;
        hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x()));
        vBar->setValue(vBar->value() - delta.y());
        mPrevMousePos = event->pos();
    }

    QGraphicsView::mouseMoveEvent(event);
}
Example #27
0
void QWellArray::paintEvent(QPaintEvent *e)
{
    QRect r = e->rect();
    int cx = r.x();
    int cy = r.y();
    int ch = r.height();
    int cw = r.width();
    int colfirst = columnAt(cx);
    int collast = columnAt(cx + cw);
    int rowfirst = rowAt(cy);
    int rowlast = rowAt(cy + ch);

    if (isRightToLeft()) {
        int t = colfirst;
        colfirst = collast;
        collast = t;
    }

    QPainter painter(this);
    QPainter *p = &painter;
    QRect rect(0, 0, cellWidth(), cellHeight());

    if (collast < 0 || collast >= ncols)
        collast = ncols-1;
    if (rowlast < 0 || rowlast >= nrows)
        rowlast = nrows-1;

    // Go through the rows
    for (int r = rowfirst; r <= rowlast; ++r) {
        // get row position and height
        int rowp = rowY(r);

        // Go through the columns in the row r
        // if we know from where to where, go through [colfirst, collast],
        // else go through all of them
        for (int c = colfirst; c <= collast; ++c) {
            if (ncols*r+c >= ncells)
                return;

            // get position and width of column c
            int colp = columnX(c);
            // Translate painter and draw the cell
            rect.translate(colp, rowp);
            paintCell(p, r, c, rect);
            rect.translate(-colp, -rowp);
        }
    }
}
Example #28
0
QSize TabBar::tabSizeHint(int index) const
{
    if (!isVisible()) {
        return QSize(-1, -1);
    }

    const int maxWidth = 250;
    const int minWidth = 100;
    const int minHeight = 27;

    TabBar* tabBar = const_cast<TabBar*>(this);

    QSize size = QTabBar::tabSizeHint(index);
    size.setHeight(qMax(size.height(), minHeight));

    int availableWidth = width() - (m_addTabButton->isVisible() ? m_addTabButton->width() : 0);
    int tabCount = count();
    int boundedWidthForTab = maxWidth;
    int activeTabWidth = boundedWidthForTab;

    if (tabCount > 0) {
        boundedWidthForTab = qBound(minWidth, availableWidth / tabCount, maxWidth);
        if (index == currentIndex()) {
            activeTabWidth = qBound(boundedWidthForTab, availableWidth - (tabCount - 1) * boundedWidthForTab, maxWidth);
            size.setWidth(activeTabWidth);
        }
        else {
            size.setWidth(boundedWidthForTab);
        }
    }

    if (index == tabCount - 1) {
        if (tabCount * boundedWidthForTab > availableWidth) {
            m_addTabButton->hide();
        }
        else {
            int addTabButtonX = (tabCount - 1) * boundedWidthForTab + activeTabWidth;

            if (isRightToLeft()) {
                addTabButtonX = width() - addTabButtonX;
            }

            tabBar->moveAddTabButton(addTabButtonX);
            m_addTabButton->show();
        }
    }
    return size;
}
Example #29
0
void ColorWidget::resizeEvent(QResizeEvent *event)
{
	QWidget::resizeEvent(event);

	layout()->setContentsMargins((m_lineEditWidget->height() + 2), 0, 0, 0);

	m_buttonRectangle = rect();

	if (isRightToLeft())
	{
		m_buttonRectangle.setLeft(m_buttonRectangle.right() - m_lineEditWidget->height());
	}
	else
	{
		m_buttonRectangle.setRight(m_lineEditWidget->height());
	}

	m_buttonRectangle.adjust(2, 2, -2, -2);
}
Example #30
0
/*!
    \reimp
 */
void QTabWidget::keyPressEvent(QKeyEvent *e)
{
    Q_D(QTabWidget);
    if (((e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) &&
          count() > 1 && e->modifiers() & Qt::ControlModifier)
#ifdef QT_KEYPAD_NAVIGATION
          || QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) && count() > 1
#endif
       ) {
        int pageCount = d->tabs->count();
        int page = currentIndex();
        int dx = (e->key() == Qt::Key_Backtab || e->modifiers() & Qt::ShiftModifier) ? -1 : 1;
#ifdef QT_KEYPAD_NAVIGATION
        if (QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))
            dx = e->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1;
#endif
        for (int pass = 0; pass < pageCount; ++pass) {
            page+=dx;
            if (page < 0
#ifdef QT_KEYPAD_NAVIGATION
                && !e->isAutoRepeat()
#endif
               ) {
                page = count() - 1;
            } else if (page >= pageCount
#ifdef QT_KEYPAD_NAVIGATION
                       && !e->isAutoRepeat()
#endif
                      ) {
                page = 0;
            }
            if (d->tabs->isTabEnabled(page)) {
                setCurrentIndex(page);
                break;
            }
        }
        if (!qApp->focusWidget())
            d->tabs->setFocus();
    } else {
        e->ignore();
    }
}