void View::resizeEvent( QResizeEvent * event ) { if ( QGraphicsScene * scene_ = scene() ) scene_->setSceneRect( 0, 0, viewport()->width(), viewport()->height() ); QGraphicsView::resizeEvent(event); }
void HistogramView::dataChanged(const QModelIndex &topLeft,const QModelIndex &bottomRight) { QAbstractItemView::dataChanged(topLeft,bottomRight); viewport()->update(); }
// paintEvent()函数具体完成柱状统计图绘制的工作 void HistogramView::paintEvent(QPaintEvent *) { QPainter painter(viewport()); painter.setPen(Qt::black); int x0=40; int y0=250; //y坐标轴 painter.drawLine(x0,y0,40,30); painter.drawLine(38,32,40,30); painter.drawLine(40,30,42,32); painter.drawText(20,30,tr("人数")); for(int i=1;i<5;i++) { painter.drawLine(-1,-i*50,1,-i*50); painter.drawText(-20,-i*50,tr("%1").arg(i*5)); } //x 坐标轴 painter.drawLine(x0,y0,540,250); painter.drawLine(538,248,540,250); painter.drawLine(540,250,538,252); painter.drawText(545,250,tr("部门")); int posD=x0+20; int row; for(row=0;row<model()->rowCount(rootIndex());row++) { QModelIndex index=model()->index(row,0,rootIndex()); QString dep=model()->data(index).toString(); painter.drawText(posD,y0+20,dep); posD+=50; } //男 int posM=x0+20; for(row=0;row<model()->rowCount(rootIndex());row++) { QModelIndex index=model()->index(row,1,rootIndex()); int male=model()->data(index).toDouble(); int width=10; if(selections->isSelected(index)) painter.setBrush(QBrush(Qt::blue,Qt::Dense3Pattern)); else painter.setBrush(Qt::blue); painter.drawRect(QRect(posM,y0-male*10,width,male*10)); QRegion regionM(posM,y0-male*10,width,male*10); MRegionList<<regionM; posM+=50; } //女 int posF=x0+30; for(row=0;row<model()->rowCount(rootIndex());row++) { QModelIndex index=model()->index(row,2,rootIndex()); int female=model()->data(index).toDouble(); int width=10; if(selections->isSelected(index)) painter.setBrush(QBrush(Qt::red,Qt::Dense3Pattern)); else painter.setBrush(Qt::red); painter.drawRect(QRect(posF,y0-female*10,width,female*10)); QRegion regionF(posF,y0-female*10,width,female*10); FRegionList<<regionF; posF+=50; } //退休 int posS=x0+40; for(row=0;row<model()->rowCount(rootIndex());row++) { QModelIndex index=model()->index(row,3,rootIndex()); int retire=model()->data(index).toDouble(); int width=10; if(selections->isSelected(index)) painter.setBrush(QBrush(Qt::green,Qt::Dense3Pattern)); else painter.setBrush(Qt::green); painter.drawRect(QRect(posS,y0-retire*10,width,retire*10)); QRegion regionS(posS,y0-retire*10,width,retire*10); SRegionList<<regionS; posS+=50; } }
void GraphicsDImgView::finishPanning() { emit contentsMoved(true); viewport()->unsetCursor(); }
void MsgViewBase::update() { if (m_updated.empty()) return; unsigned i; for (i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; unsigned id = messageId(s.left(n), client); list<Msg_Id>::iterator it; for (it = m_updated.begin(); it != m_updated.end(); ++it){ if (((*it).id == id) && ((*it).client == client)) break; } if (it != m_updated.end()) break; } m_updated.clear(); if (i >= (unsigned)paragraphs()) return; int x = contentsX(); int y = contentsY(); viewport()->setUpdatesEnabled(false); unsigned start = i; list<Msg_Id> msgs; for (; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; unsigned id = messageId(s.left(n), client); list<Msg_Id>::iterator it; for (it = msgs.begin(); it != msgs.end(); ++it){ if (((*it).id == id) && ((*it).client == client)) break; } if (it != msgs.end()) continue; Msg_Id m_id; m_id.id = id; m_id.client = client; msgs.push_back(m_id); } int paraFrom, indexFrom; int paraTo, indexTo; getSelection(¶From, &indexFrom, ¶To, &indexTo); setReadOnly(false); setSelection(start, 0, paragraphs() - 1, 0xFFFF, 0); removeSelectedText(); setReadOnly(true); QString text; for (list<Msg_Id>::iterator it = msgs.begin(); it != msgs.end(); ++it){ Message *msg = History::load((*it).id, (*it).client.c_str(), m_id); if (msg == NULL) continue; bool bUnread = false; for (list<msg_id>::iterator itu = CorePlugin::m_plugin->unread.begin(); itu != CorePlugin::m_plugin->unread.end(); ++itu){ msg_id &m = (*itu); if ((m.contact == msg->contact()) && (m.id == msg->id()) && (m.client == msg->client())){ bUnread = true; break; } } text += messageText(msg, bUnread); } viewport()->setUpdatesEnabled(true); append(text); if (!CorePlugin::m_plugin->getOwnColors()) setBackground(i); if ((paraFrom != paraTo) || (indexFrom != indexTo)) setSelection(paraFrom, indexFrom, paraTo, indexTo, 0); TextShow::sync(); setContentsPos(x, y); viewport()->repaint(); }
bool KFollowWindow::eventFilter( QObject *obj, QEvent *e ) { Q_D(KFollowWindow); if(d->target == NULL) return false; if(obj == d->target->viewport()) { switch(e->type()) { case QEvent::WindowActivate: { int i = 0; } break; case QEvent::WindowDeactivate: { if(!isVisible()) { return false; } if(d->hideFlags & TargetWindowInactive) { bool bAborted = false; emit aboutToHide(TargetWindowInactive, &bAborted); if(!bAborted) { QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection); } } } break; case QEvent::MouseButtonPress: { if(!isVisible()) { return false; } if(d->target->isUnderMouse()) { if(d->hideFlags & ClickAtTarget) { bool bAborted = false; emit aboutToHide(ClickAtTarget, &bAborted); if(!bAborted) { QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection); } } } else { if(d->hideFlags & ClickAtOther) { bool bAborted = false; emit aboutToHide(ClickAtOther, &bAborted); if(!bAborted) { QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection); } } } } break; case QEvent::Move: { if(!isVisible()) { return false; } if(d->hideFlags & TargetWindowMoving) { bool bAborted = false; emit aboutToHide(TargetWindowMoving, &bAborted); if(!bAborted) { QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection); } } } break; case QEvent::Resize: { if(!isVisible()) { return false; } if(d->hideFlags & TargetWindowResize) { bool bAborted = false; emit aboutToHide(TargetWindowResize, &bAborted); if(!bAborted) { QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection); } } } break; case QEvent::ParentChange: { } break; case QEvent::ZOrderChange: { } break; } } else if(obj == viewport()) { switch(e->type()) { case QEvent::MouseButtonPress: { if(!isVisible()) { return false; } if(d->hideFlags & ClickAtMySelf) { bool bAborted = false; emit aboutToHide(ClickAtMySelf, &bAborted); if(!bAborted) { QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection); } } } break; case QEvent::WindowActivate: { int i = 0; } break; case QEvent::WindowDeactivate: { if(!isVisible()) { return false; } if(d->hideFlags & MySelfWindowActiveToInactive) { bool bAborted = false; emit aboutToHide(MySelfWindowActiveToInactive, &bAborted); if(!bAborted) { QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection); } } } break; } } return false; }
// setup matrices and viewport (upto you to push and pop view before and after) // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight()) // if nearDist or farDist are 0 assume defaults (calculated based on width / height) void ofCairoRenderer::viewport(ofRectangle v){ viewport(v.x,v.y,v.width,v.height); }
void QHexEdit::setHighlightingColor(const QColor &color) { _brushHighlighted = QBrush(color); _penHighlighted = QPen(viewport()->palette().color(QPalette::WindowText)); viewport()->update(); }
void QHexEdit::setSelectionColor(const QColor &color) { _brushSelection = QBrush(color); _penSelection = QPen(Qt::white); viewport()->update(); }
void QHexEdit::setAsciiArea(bool asciiArea) { _asciiArea = asciiArea; viewport()->update(); }
void QHexEdit::setHighlighting(bool highlighting) { _highlighting = highlighting; viewport()->update(); }
void ByteViewText::paintEvent(QPaintEvent *) { QPainter painter(viewport()); painter.translate(-horizontalScrollBar()->value() * font_width_, 0); // Pixel offset of this row int row_y = 0; // Starting byte offset int offset = verticalScrollBar()->value() * row_width_; // Clear the area painter.fillRect(viewport()->rect(), palette().base()); // Offset background. We want the entire height to be filled. if (show_offset_) { QRect offset_rect = QRect(viewport()->rect()); offset_rect.setWidth(offsetPixels()); painter.fillRect(offset_rect, palette().window()); } if ( data_.isEmpty() ) { return; } // Data rows int widget_height = height(); int leading = fontMetrics().leading(); painter.save(); x_pos_to_column_.clear(); while( (int) (row_y + line_height_) < widget_height && offset < (int) data_.count()) { drawLine(&painter, offset, row_y); offset += row_width_; row_y += line_height_ + leading; } painter.restore(); // We can't do this in drawLine since the next line might draw over our rect. if (!hover_outlines_.isEmpty()) { qreal pen_width = 1.0; qreal hover_alpha = 0.6; QPen ho_pen; QColor ho_color = palette().text().color(); if (marked_byte_offset_ < 0) { hover_alpha = 0.3; if (devicePixelRatio() > 1) { pen_width = 0.5; } } ho_pen.setWidthF(pen_width); ho_color.setAlphaF(hover_alpha); ho_pen.setColor(ho_color); painter.save(); painter.setPen(ho_pen); painter.setBrush(Qt::NoBrush); foreach (QRect ho_rect, hover_outlines_) { // These look good on retina and non-retina displays on macOS. // We might want to use fontMetrics numbers instead. ho_rect.adjust(-1, 0, -1, -1); painter.drawRect(ho_rect); }
void ByteViewText::markAppendix(int start, int length) { field_a_start_ = start; field_a_len_ = length; viewport()->update(); }
void ByteViewText::markProtocol(int start, int length) { proto_start_ = start; proto_len_ = length; viewport()->update(); }
void ByteViewText::setFieldAppendixHighlight(int start, int end) { fa_bound_ = QPair<guint, guint>(qMax(0, start), qMax(0, end)); fa_bound_save_ = f_bound_; viewport()->update(); }
// ********************************************************************** Handle events void QHexEdit::keyPressEvent(QKeyEvent *event) { // Cursor movements if (event->matches(QKeySequence::MoveToNextChar)) { setCursorPosition(_cursorPosition + 1); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousChar)) { setCursorPosition(_cursorPosition - 1); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToEndOfLine)) { setCursorPosition(_cursorPosition | (2 * BYTES_PER_LINE -1)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfLine)) { setCursorPosition(_cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousLine)) { setCursorPosition(_cursorPosition - (2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextLine)) { setCursorPosition(_cursorPosition + (2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextPage)) { setCursorPosition(_cursorPosition + (((_rowsShown - 1) * 2 * BYTES_PER_LINE))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousPage)) { setCursorPosition(_cursorPosition - (((_rowsShown - 1) * 2 * BYTES_PER_LINE))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToEndOfDocument)) { setCursorPosition(_chunks->size() * 2); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfDocument)) { setCursorPosition(0); resetSelection(_cursorPosition); } // Select commands if (event->matches(QKeySequence::SelectAll)) { resetSelection(0); setSelection(2*_chunks->size() + 1); } if (event->matches(QKeySequence::SelectNextChar)) { qint64 pos = _cursorPosition + 1; setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousChar)) { qint64 pos = _cursorPosition - 1; setSelection(pos); setCursorPosition(pos); } if (event->matches(QKeySequence::SelectEndOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)) + (2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousLine)) { qint64 pos = _cursorPosition - (2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextLine)) { qint64 pos = _cursorPosition + (2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextPage)) { qint64 pos = _cursorPosition + (((viewport()->height() / _pxCharHeight) - 1) * 2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousPage)) { qint64 pos = _cursorPosition - (((viewport()->height() / _pxCharHeight) - 1) * 2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectEndOfDocument)) { qint64 pos = _chunks->size() * 2; setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfDocument)) { qint64 pos = 0; setCursorPosition(pos); setSelection(pos); } // Edit Commands if (!_readOnly) { if ((QApplication::keyboardModifiers() == Qt::NoModifier) || (QApplication::keyboardModifiers() == Qt::KeypadModifier)) { /* Hex input */ int key = int(event->text()[0].toLatin1()); if ((key>='0' && key<='9') || (key>='a' && key <= 'f')) { if (getSelectionBegin() != getSelectionEnd()) { if (_overwriteMode) { qint64 len = getSelectionEnd() - getSelectionBegin(); replace(getSelectionBegin(), (int)len, QByteArray((int)len, char(0))); } else { remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()); _bPosCurrent = getSelectionBegin(); } setCursorPosition(2*_bPosCurrent); resetSelection(2*_bPosCurrent); } // If insert mode, then insert a byte if (_overwriteMode == false) if ((_cursorPosition % 2) == 0) insert(_bPosCurrent, char(0)); // Change content if (_chunks->size() > 0) { QByteArray hexValue = _chunks->data(_bPosCurrent, 1).toHex(); if ((_cursorPosition % 2) == 0) hexValue[0] = key; else hexValue[1] = key; replace(_bPosCurrent, QByteArray().fromHex(hexValue)[0]); setCursorPosition(_cursorPosition + 1); resetSelection(_cursorPosition); } } } /* Cut */ if (event->matches(QKeySequence::Cut)) { QByteArray ba = _chunks->data(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()).toHex(); for (qint64 idx = 32; idx < ba.size(); idx +=33) ba.insert(idx, "\n"); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(ba); if (_overwriteMode) { qint64 len = getSelectionEnd() - getSelectionBegin(); replace(getSelectionBegin(), (int)len, QByteArray((int)len, char(0))); } else { remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()); } setCursorPosition(2*getSelectionBegin()); resetSelection(2*getSelectionBegin()); } /* Paste */ if (event->matches(QKeySequence::Paste)) { QClipboard *clipboard = QApplication::clipboard(); QByteArray ba = QByteArray().fromHex(clipboard->text().toLatin1()); if (_overwriteMode) replace(_bPosCurrent, ba.size(), ba); else insert(_bPosCurrent, ba); setCursorPosition(_cursorPosition + 2 * ba.size()); resetSelection(getSelectionBegin()); } /* Delete char */ if (event->matches(QKeySequence::Delete)) { if (getSelectionBegin() != getSelectionEnd()) { _bPosCurrent = getSelectionBegin(); if (_overwriteMode) { QByteArray ba = QByteArray(getSelectionEnd() - getSelectionBegin(), char(0)); replace(_bPosCurrent, ba.size(), ba); } else { remove(_bPosCurrent, getSelectionEnd() - getSelectionBegin()); } } else { if (_overwriteMode) replace(_bPosCurrent, char(0)); else remove(_bPosCurrent, 1); } setCursorPosition(2 * _bPosCurrent); resetSelection(2 * _bPosCurrent); } /* Backspace */ if ((event->key() == Qt::Key_Backspace) && (event->modifiers() == Qt::NoModifier)) { if (getSelectionBegin() != getSelectionEnd()) { _bPosCurrent = getSelectionBegin(); setCursorPosition(2 * _bPosCurrent); if (_overwriteMode) { QByteArray ba = QByteArray(getSelectionEnd() - getSelectionBegin(), char(0)); replace(_bPosCurrent, ba.size(), ba); } else { remove(_bPosCurrent, getSelectionEnd() - getSelectionBegin()); } resetSelection(2 * _bPosCurrent); } else { _bPosCurrent -= 1; if (_overwriteMode) replace(_bPosCurrent, char(0)); else remove(_bPosCurrent, 1); _bPosCurrent -= 1; setCursorPosition(2 * _bPosCurrent); resetSelection(2 * _bPosCurrent); } } /* undo */ if (event->matches(QKeySequence::Undo)) { undo(); } /* redo */ if (event->matches(QKeySequence::Redo)) { redo(); } } /* Copy */ if (event->matches(QKeySequence::Copy)) { QByteArray ba = _chunks->data(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()).toHex(); for (qint64 idx = 32; idx < ba.size(); idx +=33) ba.insert(idx, "\n"); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(ba); } // Switch between insert/overwrite mode if ((event->key() == Qt::Key_Insert) && (event->modifiers() == Qt::NoModifier)) { setOverwriteMode(!overwriteMode()); setCursorPosition(_cursorPosition); } refresh(); }
void ByteViewText::setEncoding(packet_char_enc encoding) { encoding_ = encoding; viewport()->update(); }
void QHexEdit::setAddressAreaColor(const QColor &color) { _addressAreaColor = color; viewport()->update(); }
KFollowWindow::~KFollowWindow() { Q_D(KFollowWindow); viewport()->removeEventFilter(this); }
void QHexEdit::paintEvent(QPaintEvent *event) { QPainter painter(viewport()); if (event->rect() != _cursorRect) { // process some useful calculations int pxOfsX = horizontalScrollBar()->value(); int pxPosStartY = _pxCharHeight; // draw some patterns if needed painter.fillRect(event->rect(), viewport()->palette().color(QPalette::Base)); if (_addressArea) painter.fillRect(QRect(-pxOfsX, event->rect().top(), _pxPosHexX - _pxGapAdrHex/2 - pxOfsX, height()), _addressAreaColor); if (_asciiArea) { int linePos = _pxPosAsciiX - (_pxGapHexAscii / 2); painter.setPen(Qt::gray); painter.drawLine(linePos - pxOfsX, event->rect().top(), linePos - pxOfsX, height()); } painter.setPen(viewport()->palette().color(QPalette::WindowText)); // paint address area if (_addressArea) { QString address; for (int row=0, pxPosY = _pxCharHeight; row <= (_dataShown.size()/BYTES_PER_LINE); row++, pxPosY +=_pxCharHeight) { address = QString("%1").arg(_bPosFirst + row*BYTES_PER_LINE + _addressOffset, _addrDigits, 16, QChar('0')); painter.drawText(_pxPosAdrX - pxOfsX, pxPosY, address); } } // paint hex and ascii area QPen colStandard = QPen(viewport()->palette().color(QPalette::WindowText)); painter.setBackgroundMode(Qt::TransparentMode); for (int row = 0, pxPosY = pxPosStartY; row <= _rowsShown; row++, pxPosY +=_pxCharHeight) { QByteArray hex; int pxPosX = _pxPosHexX - pxOfsX; int pxPosAsciiX2 = _pxPosAsciiX - pxOfsX; qint64 bPosLine = row * BYTES_PER_LINE; for (int colIdx = 0; ((bPosLine + colIdx) < _dataShown.size() && (colIdx < BYTES_PER_LINE)); colIdx++) { QColor c = viewport()->palette().color(QPalette::Base); painter.setPen(colStandard); qint64 posBa = _bPosFirst + bPosLine + colIdx; if ((getSelectionBegin() <= posBa) && (getSelectionEnd() > posBa)) { c = _brushSelection.color(); painter.setPen(_penSelection); } else { if (_highlighting) if (_markedShown.at((int)(posBa - _bPosFirst))) { c = _brushHighlighted.color(); painter.setPen(_penHighlighted); } } // render hex value QRect r; if (colIdx == 0) r.setRect(pxPosX, pxPosY - _pxCharHeight + _pxSelectionSub, 2*_pxCharWidth, _pxCharHeight); else r.setRect(pxPosX - _pxCharWidth, pxPosY - _pxCharHeight + _pxSelectionSub, 3*_pxCharWidth, _pxCharHeight); painter.fillRect(r, c); hex = _hexDataShown.mid((bPosLine + colIdx) * 2, 2); painter.setPen(QColor::fromRgb(0, 128, 0)); painter.drawText(pxPosX, pxPosY, hex); pxPosX += 3*_pxCharWidth; // render ascii value if (_asciiArea) { char ch = _dataShown.at(bPosLine + colIdx); if ((ch < 0x20) || (ch > 0x7e)) ch = '.'; r.setRect(pxPosAsciiX2, pxPosY - _pxCharHeight + _pxSelectionSub, _pxCharWidth, _pxCharHeight); painter.fillRect(r, c); painter.drawText(pxPosAsciiX2, pxPosY, QChar(ch)); pxPosAsciiX2 += _pxCharWidth; } } } painter.setBackgroundMode(Qt::TransparentMode); painter.setPen(viewport()->palette().color(QPalette::WindowText)); } // paint cursor if (_blink && !_readOnly && hasFocus()) painter.fillRect(_cursorRect, this->palette().color(QPalette::WindowText)); else painter.drawText(_pxCursorX, _pxCursorY, _hexDataShown.mid(_cursorPosition - _bPosFirst * 2, 1)); // emit event, if size has changed if (_lastEventSize != _chunks->size()) { _lastEventSize = _chunks->size(); emit currentSizeChanged(_lastEventSize); } }
void GraphicsDImgView::scrollContentsBy(int dx, int dy) { QGraphicsView::scrollContentsBy(dx, dy); emit viewportRectChanged(mapToScene(viewport()->rect()).boundingRect()); }
QRectF CanvasContainer::visualRect() const { return proxy->mapFromScene( mapToScene(viewport()->rect())) .boundingRect().intersected(proxy->rect()); }
QRect GraphicsDImgView::visibleArea() const { return (mapToScene(viewport()->geometry()).boundingRect().toRect()); }
QWidget* CanvasContainer::scaleSlider() { if (!scaleSliderWidget) { scaleSliderWidget = new QWidget(this); QHBoxLayout *layout = new QHBoxLayout(scaleSliderWidget); QSlider *slider = new QSlider(Qt::Horizontal, scaleSliderWidget); QLabel *label = new QLabel("100%", scaleSliderWidget); label->setFixedWidth(label->fontMetrics().width("100.%")); label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); //label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); //not working? scaleSliderWidget->setLayout(layout); layout->addWidget(slider); layout->addWidget(label); layout->setContentsMargins(0, 0, 0, 0); qreal internalFactor = -100 * qLn(MIN_SCALE_FACTOR) / MIN_SCALE_FACTOR / qLn(2); slider->setRange(-qCeil(MIN_SCALE_FACTOR * internalFactor), qCeil(MAX_SCALE_FACTOR - 1) * 100); slider->setPageStep(100); slider->setTickPosition(QSlider::TicksBelow); auto setScaleOrigin = [=]() { if (proxy) { QPointF position = proxy->mapFromScene(mapToScene(viewport()->rect().center())); if (proxy->rect().contains(position)) proxy->setTransformOriginPoint(position); } }; auto calculateScale = [=](int sliderValue) { if (sliderValue >= 0) { qreal newScale = 1.0 + 0.01 * sliderValue; if (!qFuzzyCompare(newScale, currentScaleFactor())) { setScaleOrigin(); setScaleFactor(1.0 + 0.01 * sliderValue); label->setText(QString("%1%").arg(100 + sliderValue)); } } else { qreal newScale = qPow(MIN_SCALE_FACTOR, -sliderValue / internalFactor / MIN_SCALE_FACTOR); if (!qFuzzyCompare(newScale, currentScaleFactor())) { setScaleOrigin(); setScaleFactor(newScale); label->setText(QString("%1%").arg(newScale * 100, 0, 'f', 1)); } } }; auto calculateValue = [=](qreal scaleFactor) { slider->blockSignals(true); if (scaleFactor >= 1.0) { int newValue = 100 * scaleFactor - 100; if (newValue != slider->value()) { slider->setValue(newValue); label->setText(QString("%1%").arg(qFloor(100 * scaleFactor))); } } else { int newValue = -internalFactor * MIN_SCALE_FACTOR / qLn(MIN_SCALE_FACTOR) * qLn(scaleFactor); if (newValue != slider->value()) { slider->setValue(newValue); label->setText(QString("%1%").arg(100 * scaleFactor, 0, 'f', 1)); } } slider->blockSignals(false); }; connect(slider, &QSlider::valueChanged, calculateScale); connect(this, &CanvasContainer::scaled, calculateValue); } return scaleSliderWidget; }
void *MsgViewBase::processEvent(Event *e) { if ((e->type() == EventRewriteMessage) || (e->type() == EventMessageRead)){ Message *msg = (Message*)(e->param()); if (msg->contact() != m_id) return NULL; unsigned i; for (i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; if ((messageId(s.left(n), client) == msg->id()) && (client == msg->client())) break; } if (i >= (unsigned)paragraphs()) return NULL; Msg_Id id; id.id = msg->id(); id.client = msg->client(); m_updated.push_back(id); QTimer::singleShot(0, this, SLOT(update())); return NULL; } if (e->type() == EventCutHistory){ CutHistory *ch = (CutHistory*)(e->param()); if (ch->contact != m_id) return NULL; bool bDelete = false; vector<unsigned> start_pos; vector<unsigned> end_pos; for (unsigned i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; unsigned id = messageId(s.left(n), client); if ((client == ch->client) && (id >= ch->from) && (id < ch->from + ch->size)){ if (!bDelete){ bDelete = true; start_pos.push_back(i); } }else{ if (bDelete){ bDelete = false; end_pos.push_back(i); } } } if (bDelete) end_pos.push_back(paragraphs()); if (start_pos.size()){ int paraFrom, indexFrom; int paraTo, indexTo; getSelection(¶From, &indexFrom, ¶To, &indexTo); QPoint p = QPoint(0, 0); p = mapToGlobal(p); p = viewport()->mapFromGlobal(p); int x, y; viewportToContents(p.x(), p.y(), x, y); int para; int pos = charAt(QPoint(x, y), ¶); setReadOnly(false); for (unsigned i = 0; i < start_pos.size(); i++){ setSelection(start_pos[i], 0, end_pos[i], 0, 0); removeSelectedText(); if ((unsigned)pos >= start_pos[i]) pos = end_pos[i] - start_pos[i]; } if ((paraFrom == -1) && (paraTo == -1)){ if (pos == -1){ scrollToBottom(); }else{ setCursorPosition(para, pos); ensureCursorVisible(); } }else{ setSelection(paraFrom, indexFrom, paraTo, indexTo, 0); } setReadOnly(true); repaint(); } m_cut.push_back(*ch); return NULL; } if (e->type() == EventMessageDeleted){ Message *msg = (Message*)(e->param()); if (msg->contact() != m_id) return NULL; for (unsigned i = 0; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; if ((messageId(s.left(n), client) != msg->id()) || (client != msg->client())) continue; string ss; ss = text(i).local8Bit(); log(L_DEBUG, "?: %s", ss.c_str()); unsigned j; for (j = i + 1; j < (unsigned)paragraphs(); j++){ QString s = text(j); ss = text(j).local8Bit(); log(L_DEBUG, ">: %s", ss.c_str()); int n = s.find(MSG_ANCHOR); if (n < 0) continue; s = s.mid(n + strlen(MSG_ANCHOR)); n = s.find("\""); if (n < 0) continue; string client; if ((messageId(s.left(n), client) != msg->id()) || (client != msg->client())) break; } int paraFrom, indexFrom; int paraTo, indexTo; getSelection(¶From, &indexFrom, ¶To, &indexTo); unsigned pos = 0xFFFF; if (j == (unsigned)paragraphs()){ j++; pos = 0; } setSelection(i, 0, j - 1, pos, 0); setReadOnly(false); removeSelectedText(); setReadOnly(true); if ((paraFrom == -1) && (paraTo == -1)){ scrollToBottom(); }else{ setSelection(paraFrom, indexFrom, paraTo, indexTo, 0); } break; } return NULL; } if (e->type() == EventHistoryConfig){ unsigned id = (unsigned)(e->param()); if (id && (id != m_id)) return NULL; reload(); } if (e->type() == EventHistoryColors) setColors(); if (e->type() == EventCheckState){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->param != this) || (cmd->menu_id != MenuMsgView)) return NULL; Message *msg; switch (cmd->id){ case CmdCopy: cmd->flags &= ~(COMMAND_DISABLED | COMMAND_CHECKED); if (!hasSelectedText()) cmd->flags |= COMMAND_DISABLED; return e->param(); case CmdMsgOpen: msg = currentMessage(); if (msg){ unsigned type = msg->baseType(); delete msg; CommandDef *def = CorePlugin::m_plugin->messageTypes.find(type); if (def == NULL) return NULL; cmd->icon = def->icon; cmd->flags &= ~COMMAND_CHECKED; return e->param(); } return NULL; case CmdMsgSpecial: msg = currentMessage(); if (msg){ Event eMenu(EventGetMenuDef, (void*)MenuMsgCommand); CommandsDef *cmdsMsg = (CommandsDef*)(eMenu.process()); unsigned n = 0; MessageDef *mdef = NULL; unsigned type = msg->baseType(); const CommandDef *cmdsSpecial = NULL; CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type); if (msgCmd) mdef = (MessageDef*)(msgCmd->param); if (mdef){ if (msg->getFlags() & MESSAGE_RECEIVED){ cmdsSpecial = mdef->cmdReceived; }else{ cmdsSpecial = mdef->cmdSent; } if (cmdsSpecial) for (const CommandDef *d = cmdsSpecial; d->text; d++) n++; } { CommandsList it(*cmdsMsg, true); while (++it) n++; } if (n == 0) return NULL; n++; CommandDef *cmds = new CommandDef[n]; memset(cmds, 0, sizeof(CommandDef) * n); n = 0; if (cmdsSpecial){ for (const CommandDef *d = cmdsSpecial; d->text; d++){ cmds[n] = *d; cmds[n].id = CmdMsgSpecial + n; cmds[n].flags = COMMAND_DEFAULT; n++; } } CommandDef *c; CommandsList it(*cmdsMsg, true); while ((c = ++it) != NULL){ CommandDef cmd = *c; cmd.menu_id = MenuMsgCommand; cmd.param = msg; Event e(EventCheckState, &cmd); if (!e.process()) continue; cmd.flags &= ~COMMAND_CHECK_STATE; cmds[n++] = cmd; } cmd->param = cmds; cmd->flags |= COMMAND_RECURSIVE; delete msg; return e->param(); } return NULL; } } if (e->type() == EventCommandExec){ CommandDef *cmd = (CommandDef*)(e->param()); if ((cmd->param != this) || (cmd->menu_id != MenuMsgView)) return NULL; Message *msg; switch (cmd->id){ case CmdCutHistory: msg = currentMessage(); if (msg){ History::cut(msg, 0, 0); delete msg; return e->param(); } return NULL; case CmdDeleteMessage: msg = currentMessage(); if (msg){ History::del(msg); delete msg; return e->param(); } return NULL; case CmdCopy: copy(); return e->param(); case CmdMsgOpen: msg = currentMessage(); if (msg){ msg->setFlags(msg->getFlags() | MESSAGE_OPEN); Event eOpen(EventOpenMessage, &msg); eOpen.process(); delete msg; return e->param(); } return NULL; default: msg = currentMessage(); if (msg){ if (cmd->id >= CmdMsgSpecial){ MessageDef *mdef = NULL; unsigned type = msg->baseType(); CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type); if (msgCmd) mdef = (MessageDef*)(msgCmd->param); const CommandDef *cmds = NULL; if (mdef){ if (msg->getFlags() & MESSAGE_RECEIVED){ cmds = mdef->cmdReceived; }else{ cmds = mdef->cmdSent; } } if (cmds){ unsigned n = cmd->id - CmdMsgSpecial; for (const CommandDef *d = cmds; d->text; d++){ if (n-- == 0){ CommandDef cmd = *d; cmd.param = msg; cmd.menu_id = 0; Event eCmd(EventCommandExec, &cmd); eCmd.process(); return e->param(); } } } } Command c; c->id = cmd->id; c->menu_id = MenuMsgCommand; c->param = msg; Event e(EventCommandExec, c); void *res = e.process(); delete msg; return res; } return NULL; } } return NULL; }
void UIDisasm::setSelectionColor(const QColor &color) { selectionColor = color; viewport()->update(); }
void HistogramView::selectionChanged(const QItemSelection &selected,const QItemSelection &deselected) { viewport()->update(); }
void ByteViewText::setProtocolHighlight(int start, int end) { p_bound_ = QPair<guint, guint>(qMax(0, start), qMax(0, end)); p_bound_save_ = p_bound_; viewport()->update(); }
QRectF View::visibleRect() { int h = horizontalScrollBar() ? horizontalScrollBar()->height() : 0; int w = verticalScrollBar() ? verticalScrollBar()->width() : 0; return mapToScene(viewport()->rect().adjusted(0,0,-w,-h)).boundingRect(); }
void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw) { struct divecomputer *dc; if (d) dc = select_dc(&d->dc); if (!forceRedraw && dive == d && (d && dc == diveDC)) return; clear(); dive = d; diveDC = d ? dc : NULL; if (!isVisible() || !dive) { return; } // best place to put the focus stealer code. setFocusProxy(mainWindow()->dive_list()); scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50); toolTip = new ToolTipItem(); installEventFilter(toolTip); scene()->addItem(toolTip); // Fix this for printing / screen later. // plot_set_scale(scale_mode_t); if (!dc->samples) { dc = fake_dc(dc); } QString nick = get_dc_nickname(dc->model, dc->deviceid); if (nick.isEmpty()) nick = QString(dc->model); if (nick.isEmpty()) nick = tr("unknown divecomputer"); if ( tr("unknown divecomputer") == nick){ mode = PLAN; }else{ mode = DIVE; } /* * Set up limits that are independent of * the dive computer */ calculate_max_limits(dive, dc, &gc); QRectF profile_grid_area = scene()->sceneRect(); gc.maxx = (profile_grid_area.width() - 2 * profile_grid_area.x()); gc.maxy = (profile_grid_area.height() - 2 * profile_grid_area.y()); /* This is per-dive-computer */ gc.pi = *create_plot_info(dive, dc, &gc); /* Bounding box */ QPen pen = defaultPen; pen.setColor(profile_color[TIME_GRID].at(0)); QGraphicsRectItem *rect = new QGraphicsRectItem(profile_grid_area); rect->setPen(pen); scene()->addItem(rect); /* Depth profile */ plot_depth_profile(); plot_events(dc); /* Temperature profile */ plot_temperature_profile(); /* Cylinder pressure plot */ plot_cylinder_pressure(dc); /* Text on top of all graphs.. */ plot_temperature_text(); plot_depth_text(); plot_cylinder_pressure_text(); plot_deco_text(); /* Put the dive computer name in the lower left corner */ gc.leftx = 0; gc.rightx = 1.0; gc.topy = 0; gc.bottomy = 1.0; text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, TOP}; diveComputer = plot_text(&computer, QPointF(gc.leftx, gc.bottomy), nick); // The Time ruler should be right after the DiveComputer: timeMarkers->setPos(0, diveComputer->y()); if (PP_GRAPHS_ENABLED) { plot_pp_gas_profile(); plot_pp_text(); } /* now shift the translation back by half the margin; * this way we can draw the vertical scales on both sides */ //cairo_translate(gc->cr, -drawing_area->x / 2.0, 0); //gc->maxx += drawing_area->x; //gc->leftx = -(drawing_area->x / drawing_area->width) / 2.0; //gc->rightx = 1.0 - gc->leftx; plot_depth_scale(); #if 0 if (gc->printer) { free(pi->entry); last_pi_entry = pi->entry = NULL; pi->nr = 0; } #endif QRectF r = scene()->itemsBoundingRect(); scene()->setSceneRect(r.x() - 15, r.y() -15, r.width() + 30, r.height() + 30); if (zoomLevel == 0) { fitInView(sceneRect()); } toolTip->readPos(); if(mode == PLAN){ timeEditor = new GraphicsTextEditor(); timeEditor->setPlainText( dive->duration.seconds ? QString::number(dive->duration.seconds/60) : tr("Set Duration: 10 minutes")); timeEditor->setPos(profile_grid_area.width() - timeEditor->boundingRect().width(), timeMarkers->y()); timeEditor->document(); connect(timeEditor, SIGNAL(editingFinished(QString)), this, SLOT(edit_dive_time(QString))); scene()->addItem(timeEditor); } }