/*! Invalidate the paint cache and repaint the canvas \sa invalidatePaintCache() */ void QwtPlotAbstractGLCanvas::replot() { invalidateBackingStore(); QWidget *w = canvasWidget(); if ( testPaintAttribute( QwtPlotAbstractGLCanvas::ImmediatePaint ) ) w->repaint( w->contentsRect() ); else w->update( w->contentsRect() ); }
void ModuleView::updateWidget(QWidget& widget) { { SYNC_WITH(console); if(lastModulInfoTimeStamp == console.moduleInfo.timeStamp) return; } generateImage(); ((ModuleWidget*)(&widget))->image = image; widget.update(); }
void ChromeClientQt::addToDirtyRegion(const IntRect& r) { QWidget* view = m_webPage->view(); if (view) { QRect rect(r); rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize())); if (!r.isEmpty()) view->update(r); } else emit m_webPage->repaintRequested(r); }
void views::treeView::headerRepaint() { QModelIndex index=indexAt( viewport()->mapFromGlobal(QCursor::pos() ) ); int mouseColumn=index.column(); if(mouseColumn!=header()->property("highlight") ) { mouseColumn=index.column(); header()->setProperty("highlight",QVariant(mouseColumn) ); QWidget * viewport = header()->viewport(); viewport->update(); } }
void OpenGLWidgetPrivate::render() { const qreal retinaScale = q->devicePixelRatio(); glViewport(0, 0, width() * retinaScale, height() * retinaScale); glClearColor(clearColor[0], clearColor[1], clearColor[2], 1.0f); glClear(GL_COLOR_BUFFER_BIT); m_program->bind(); QMatrix4x4 matrix; matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f); matrix.translate(0, 0, -2); const qreal angle = 100.0f * m_frame / 30; matrix.rotate(angle, m_rotAxis); m_program->setUniformValue(m_matrixUniform, matrix); GLfloat vertices[] = { 0.0f, 0.707f, -0.5f, -0.5f, 0.5f, -0.5f }; GLfloat colors[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices); glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(1); glDisableVertexAttribArray(0); m_program->release(); ++m_frame; if (m_interval <= 0) q->update(); }
/* Notify all enabled windows that the DWM state changed */ bool WindowNotifier::winEvent(MSG *message, long *result) { if (message && message->message == WM_DWMCOMPOSITIONCHANGED) { bool compositionEnabled = QtDWM::isCompositionEnabled(); WidgetsMap::iterator i = widgets.begin(); while (i != widgets.end()) { QWidget * w = i.key(); if (w) { w->setAttribute(Qt::WA_NoSystemBackground, compositionEnabled); w->update(); i.value()->reenable(); } ++i; } } return QWidget::nativeEvent("windows_generic_MSG", message, result); }
void ChromeClientQt::repaint(const IntRect& windowRect, bool contentChanged, bool immediate, bool repaintContentOnly) { // No double buffer, so only update the QWidget if content changed. if (contentChanged) { QWidget* view = m_webPage->view(); if (view) { QRect rect(windowRect); rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize())); if (!rect.isEmpty()) view->update(rect); } emit m_webPage->repaintRequested(windowRect); } // FIXME: There is no "immediate" support for window painting. This should be done always whenever the flag // is set. }
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { int row = index.row(); ItemWidget *w = m_cache[row]; if (w == NULL) return; const QRect &rect = option.rect; bool isSelected = option.state & QStyle::State_Selected; /* render background (selected, alternate, ...) */ QStyle *style = m_view->style(); style->drawControl(QStyle::CE_ItemViewItem, &option, painter, m_view); /* render number */ if (m_showRowNumber) { const QString num = QString::number(row); QPalette::ColorRole role = isSelected ? QPalette::HighlightedText : QPalette::Text; painter->save(); painter->setFont(m_rowNumberFont); style->drawItemText(painter, rect.translated(m_hMargin / 2, m_vMargin), 0, m_rowNumberPalette, true, num, role); painter->restore(); } /* highlight search string */ w->setHighlight(m_re, m_foundFont, m_foundPalette); /* text color for selected/unselected item */ QWidget *ww = w->widget(); if ( ww->property(propertySelectedItem) != isSelected ) { ww->setProperty(propertySelectedItem, isSelected); if ( !ww->property("CopyQ_no_style").toBool() ) { ww->setStyle(style); foreach (QWidget *child, ww->findChildren<QWidget *>()) child->setStyle(style); ww->update(); } } }
void RosegardenScrollView::updateContents(int x, int y, int w, int h) // Code lifted from Q3ScrollView { if (!isVisible() || !updatesEnabled()) return; // RG_DEBUG << "RosegardenScrollView::updateContents" << endl; QWidget* vp = viewport(); // Translate x -= contentsX(); y -= contentsY(); if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (w < 0 || h < 0) return; if (x > visibleWidth() || y > visibleHeight()) return; if (w > visibleWidth()) w = visibleWidth(); if (h > visibleHeight()) h = visibleHeight(); //### CJ - I don't think we used a clipped_viewport on Q3ScrollView //if (d->clipped_viewport) { //// Translate clipper() to viewport() //x -= d->clipped_viewport->x(); //y -= d->clipped_viewport->y(); //} vp->update(x, y, w, h); updateScrollBars(); }
void VirtualConsole::setSelectedWidget(QWidget* w) { if (m_selectedWidget) { QWidget* old = m_selectedWidget; m_selectedWidget = w; old->update(); } else { m_selectedWidget = w; } if (m_selectedWidget) { m_selectedWidget->update(); } else { } }
void Pageview::slotPagePartChanged (const QModelIndex &index, const QImage &image, int scaled_linenum) { const Pagedelegate *del = (Pagedelegate *)itemDelegate (); QStyleOptionViewItem option = getViewOptions (); int hvalue = horizontalScrollBar()->value(); int vvalue = verticalScrollBar()->value(); QRect rect = rectForIndex (index); QRect part_rect; option.rect = rect; del->getPagePart (option, index, scaled_linenum, image.height (), part_rect); part_rect.translate (-hvalue, -vvalue); QWidget *vp = viewport (); // qDebug () << "repaint" << part_rect; // part_rect.setHeight (part_rect.height () - 1); // leave blank line (for testing!) // vp->repaint (part_rect); vp->update (part_rect); }
void PluginView::invalidateRect(const IntRect& rect) { #if USE(ACCELERATED_COMPOSITING) && !USE(TEXTURE_MAPPER) if (m_platformLayer) { m_platformLayer->update(QRectF(rect)); return; } #endif if (m_isWindowed) { if (platformWidget()) { // update() will schedule a repaint of the widget so ensure // its knowledge of its position on the page is up to date. QWidget* w = static_cast<QWidget*>(platformWidget()); w->setGeometry(m_windowRect); w->update(rect); } return; } invalidateWindowlessPluginRect(rect); }
int runUI(int argc, char *argv[]) { QApplication a(argc,argv); QWidget *window = new QWidget; QPushButton *btn1 = new QPushButton("Hello World"); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(btn1); window->setLayout(layout); window->show(); window->update(); //QTime t; //t.start(); //while(t.elapsed()<1000) // QCoreApplication::processEvents(); window->close(); //return a.exec(); return 0; }
SignalDisplay& SignalDisplay::WrapForward( const GenericSignal& inSignal ) { if( mTargetDC == NULL ) return *this; AdaptTo( inSignal ); OSMutex::Lock lock( mDataLock ); mShowCursor = ( inSignal.Elements() < mNumSamples ); for( int i = 0; i < inSignal.Channels(); ++i ) for( int j = 0; j < inSignal.Elements(); ++j ) mData( i, ( mSampleCursor + j ) % mData.Elements() ) = inSignal( i, j ); SyncGraphics(); int firstInvalidSample = mSampleCursor, firstValidSample = mSampleCursor + inSignal.Elements(); bool wrappingAround = false; if( mNumSamples > 0 ) { wrappingAround = ( firstValidSample / mNumSamples > 0 ); mWrapAround |= wrappingAround; wrappingAround |= bool( mSampleCursor == 0 ); mSampleCursor = firstValidSample % mNumSamples; } long firstInvalidPixel = mDataRect.left(), firstValidPixel = mDataRect.right(); switch( mDisplayMode ) { case polyline: firstInvalidPixel = SampleLeft( firstInvalidSample - 1 ); firstValidPixel = SampleLeft( firstValidSample + 1 ); break; case field2d: firstInvalidPixel = SampleLeft( firstInvalidSample ); firstValidPixel = SampleLeft( firstValidSample ); break; default: bciassert( false ); } QWidget* pWindow = dynamic_cast< QWidget* >( mTargetDC ); if( pWindow ) { // Our Paint() implementation is fast for rectangular update regions but // quite slow if the update region is wrapped around the right edge. // Thus, we use repaint() rather than update() in this case. if( wrappingAround ) pWindow->repaint( mCursorRect ); else pWindow->update( mCursorRect ); QRect invalidRect = mDataRect; // The non-wrapped area. invalidRect.setLeft( max<int>( firstInvalidPixel, mDataRect.left() ) ); invalidRect.setRight( min<int>( firstValidPixel, mDataRect.right() ) ); if( invalidRect.left() < invalidRect.right() ) { if( wrappingAround ) pWindow->repaint( invalidRect ); else pWindow->update( invalidRect ); } // The area wrapped around the left edge. invalidRect.setLeft( max<int>( firstInvalidPixel + mDataWidth, mDataRect.left() ) ); invalidRect.setRight( min<int>( firstValidPixel + mDataWidth, mDataRect.right() ) ); if( invalidRect.left() < invalidRect.right() ) pWindow->repaint( invalidRect ); // The area wrapped around the right edge. invalidRect.setLeft( max<int>( firstInvalidPixel - mDataWidth, mDataRect.left() ) ); invalidRect.setRight( min<int>( firstValidPixel - mDataWidth, mDataRect.right() ) ); if( invalidRect.left() < invalidRect.right() ) pWindow->repaint( invalidRect ); if( mShowNumericValues ) { invalidRect.setLeft( mDataRect.right() - mNumericValueWidth ); invalidRect.setRight( mDataRect.right() ); if( invalidRect.left() < invalidRect.right() ) pWindow->repaint( invalidRect ); } } return *this; }
void QWidgetProto::update(int x, int y, int w, int h) { QWidget *item = qscriptvalue_cast<QWidget*>(thisObject()); if (item) item->update(x, y, w, h); }
void views::treeView::leaveEvent (QEvent *) { QWidget * viewport = header()->viewport(); header()->setProperty("highlight",QVariant(-1) ); viewport->update(); }
void QWidgetProto::update(const QRegion &rgn) { QWidget *item = qscriptvalue_cast<QWidget*>(thisObject()); if (item) item->update(rgn); }
int drv_widget(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9) { handle_head* head = (handle_head*)a0; QWidget *self = (QWidget*)head->native; switch (drvid) { case WIDGET_INIT: { drvNewObj(a0,new QWidget); break; } case WIDGET_DESTROY: { drvDelObj(a0,self); break; } case WIDGET_SETAUTODESTROY: { self->setAttribute(Qt::WA_DeleteOnClose,drvGetBool(a1)); break; } case WIDGET_AUTODESTROY: { drvSetBool(a1,self->testAttribute(Qt::WA_DeleteOnClose)); break; } case WIDGET_SETLAYOUT: { self->setLayout(drvGetLayout(a1)); break; } case WIDGET_LAYOUT: { drvSetHandle(a1,self->layout()); break; } case WIDGET_SETPARENT: { self->setParent(drvGetWidget(a1)); break; } case WIDGET_PARENT: { drvSetHandle(a1,self->parent()); break; } case WIDGET_SETVISIBLE: { self->setVisible(drvGetBool(a1)); break; } case WIDGET_ISVISIBLE: { drvSetBool(a1,self->isVisible()); break; } case WIDGET_SETWINDOWTITLE: { self->setWindowTitle(drvGetString(a1)); break; } case WIDGET_WINDOWTITLE: { drvSetString(a1,self->windowTitle()); break; } case WIDGET_SETPOS: { self->move(drvGetPoint(a1)); break; } case WIDGET_POS: { drvSetPoint(a1,self->pos()); break; } case WIDGET_SETSIZE: { self->resize(drvGetSize(a1)); break; } case WIDGET_SIZE: { drvSetSize(a1,self->size()); break; } case WIDGET_SETGEOMETRY: { self->setGeometry(drvGetRect(a1)); break; } case WIDGET_GEOMETRY: { drvSetRect(a1,self->geometry()); break; } case WIDGET_SETFONT: { self->setFont(drvGetFont(a1)); break; } case WIDGET_FONT: { drvSetFont(a1,self->font()); break; } case WIDGET_CLOSE: { self->close(); break; } case WIDGET_UPDATE: { self->update(); break; } case WIDGET_REPAINT: { self->repaint(); break; } case WIDGET_ONSHOWEVENT: { drvNewEvent(QEvent::Show,a0,a1,a2); break; } case WIDGET_ONHIDEEVENT: { drvNewEvent(QEvent::Hide,a0,a1,a2); break; } case WIDGET_ONCLOSEEVENT: { drvNewEvent(QEvent::Close,a0,a1,a2); break; } case WIDGET_ONKEYPRESSEVENT: { drvNewEvent(QEvent::KeyPress,a0,a1,a2); break; } case WIDGET_ONKEYRELEASEEVENT: { drvNewEvent(QEvent::KeyRelease,a0,a1,a2); break; } case WIDGET_ONMOUSEPRESSEVENT: { drvNewEvent(QEvent::MouseButtonPress,a0,a1,a2); break; } case WIDGET_ONMOUSERELEASEEVENT: { drvNewEvent(QEvent::MouseButtonRelease,a0,a1,a2); break; } case WIDGET_ONMOUSEMOVEEVENT: { drvNewEvent(QEvent::MouseMove,a0,a1,a2); break; } case WIDGET_ONMOUSEDOUBLECLICKEVENT: { drvNewEvent(QEvent::MouseButtonDblClick,a0,a1,a2); break; } case WIDGET_ONMOVEEVENT: { drvNewEvent(QEvent::Move,a0,a1,a2); break; } case WIDGET_ONPAINTEVENT: { drvNewEvent(QEvent::Paint,a0,a1,a2); break; } case WIDGET_ONRESIZEEVENT: { drvNewEvent(QEvent::Resize,a0,a1,a2); break; } case WIDGET_ONENTEREVENT: { drvNewEvent(QEvent::Enter,a0,a1,a2); break; } case WIDGET_ONLEAVEEVENT: { drvNewEvent(QEvent::Leave,a0,a1,a2); break; } case WIDGET_ONFOCUSINEVENT: { drvNewEvent(QEvent::FocusIn,a0,a1,a2); break; } case WIDGET_ONFOCUSOUTEVENT: { drvNewEvent(QEvent::FocusOut,a0,a1,a2); break; } default: return 0; } return 1; }
bool ShortcutHandler::eventFilter(QObject *o, QEvent *e) { if (!o->isWidgetType()) return QObject::eventFilter(o, e); QWidget *widget = static_cast<QWidget*>(o); switch(e->type()) { case QEvent::KeyPress: if (Qt::Key_Alt==static_cast<QKeyEvent *>(e)->key()) { m_altDown = true; if(qobject_cast<QMenu *>(widget)) { m_seenAlt.insert(widget); updateWidget(widget); if(widget->parentWidget() && widget->parentWidget()->window()) m_seenAlt.insert(widget->parentWidget()->window()); } else { widget = widget->window(); m_seenAlt.insert(widget); QList<QWidget*> l = widget->findChildren<QWidget*>(); for (int pos = 0;pos < l.size();++pos) { QWidget *w = l.at(pos); if (!(w->isWindow() || !w->isVisible())) // || w->style()->styleHint(QStyle::SH_UnderlineShortcut, 0, w))) updateWidget(w); } QList<QMenuBar*> m = widget->findChildren<QMenuBar*>(); for (int i = 0;i < m.size();++i) { updateWidget(m.at(i)); } } } break; case QEvent::WindowDeactivate: case QEvent::KeyRelease: if (QEvent::WindowDeactivate == e->type() || static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) { m_altDown = false; for (QWidget *widget: const_(m_updated)) { widget->update(); } if (!m_updated.contains(widget)) widget->update(); m_seenAlt.clear(); m_updated.clear(); } break; case QEvent::Show: if(qobject_cast<QMenu *>(widget)) { QWidget *prev=m_openMenus.count() ? m_openMenus.last() : 0L; m_openMenus.append(widget); if(m_altDown && prev) prev->update(); connect(widget, &QWidget::destroyed, this, &ShortcutHandler::widgetDestroyed); } break; case QEvent::Hide: if(qobject_cast<QMenu *>(widget)) { m_seenAlt.remove(widget); m_updated.remove(widget); m_openMenus.removeAll(widget); if(m_altDown) { if(m_openMenus.count()) m_openMenus.last()->update(); else if(widget->parentWidget() && widget->parentWidget()->window()) widget->parentWidget()->window()->update(); } } break; case QEvent::Close: // Reset widget when closing m_seenAlt.remove(widget); m_updated.remove(widget); m_seenAlt.remove(widget->window()); m_openMenus.removeAll(widget); if(m_altDown) { if(m_openMenus.count()) m_openMenus.last()->update(); else if(widget->parentWidget() && widget->parentWidget()->window()) widget->parentWidget()->window()->update(); } break; default: break; } return QObject::eventFilter(o, e); }
void MyLcdDisplay::readStack() { bool stateOk = systemEngine->checkState(); int visibleWidth = viewport()->size().width(); if (!lcdPixmap) { lcdPixmap = new QPixmap(visibleWidth-3,pmHeight); } lcdPixmap->fill(Qt::transparent); if ( lcdPainter ) delete lcdPainter; lcdPainter = new QPainter(); lcdPainter->begin(lcdPixmap); lcdPainter->setPen(QApplication::palette().color(QPalette::Text)); verticalOffset=0; // top margin int horizontalOffset = 10; // right margin if (!stateOk) { QRect r = QFontMetrics(QApplication::font()).boundingRect( 5, 5, visibleWidth-horizontalOffset, 80, layoutDirection() == Qt::LeftToRight ? Qt::AlignRight : Qt::AlignLeft, systemEngine->errorString); //the alignment below doesn't really matter. r already defines what is necessary lcdPainter->drawText( r, Qt::AlignRight, systemEngine->errorString ); verticalOffset=25; } else { if (Qtopia::mousePreferred()) { QPixmap *tmp; if (systemEngine->dStack.isEmpty()) return; int myoffset = 10; tmp = systemEngine->dStack.top()->draw(); int drawPoint = qMax(visibleWidth - tmp->width(),0); int srcStart = qMax(tmp->width() - visibleWidth,0); lcdPainter->drawPixmap(drawPoint - myoffset,verticalOffset,*tmp,srcStart, 0, -1, -1); verticalOffset += tmp->height(); } else { niStack = new QStack<QString*>(); ndStack = new QStack<Data*>(); while (!systemEngine->iStack.isEmpty()) niStack->push(systemEngine->iStack.pop()); while (!systemEngine->dStack.isEmpty()) ndStack->push(systemEngine->dStack.pop()); dataLeft = 1; while (!niStack->isEmpty() || !ndStack->isEmpty()) { horizontalOffset = 10; horizontalOffset = drawNextItem(horizontalOffset,true, visibleWidth); } delete niStack; delete ndStack; } } lcdPainter->end(); QWidget *w = viewport(); //w->resize(visibleWidth, verticalOffset); //w->update(0, 0, visibleWidth, verticalOffset); w->update(); }
bool FilmstripFrameHeadGadget::eventFilter(QObject *obj, QEvent *e) { if (!Preferences::instance()->isOnionSkinEnabled()) return false; QWidget *viewer = dynamic_cast<QWidget *>(obj); if (e->type() == QEvent::MouseButtonPress) { //方針:上下タブをクリック→ドラッグでオニオンスキンの増減 // 上下タブをダブルクリックでオニオンスキンの表示/非表示 // オニオンスキンの●エリア をクリックで各フレームのON/OFF切り替え→ドラッグで伸ばせる // Fixedオニオンスキンの●エリアをクリックで Fixedオニオンスキンの位置の指定 //----- それぞれのパーツの位置Rectの指定。各フレームの右上座標からのオフセットも含む。 //OnionSkinの円の左上座標のy値 int onionDotYPos = m_dy / 2 - 5; //OnionSkinの●のRect QRect onionDotRect(10, onionDotYPos, 10, 10); //FixedOnionSkinの●のRect QRect fixedOnionDotRect(0, onionDotYPos, 10, 10); //上方向のOnionSkinタブのRect QRect backOnionTabRect(0, m_dy - 15, 30, 15); //下方向のOnionSkinタブのRect QRect frontOnionTabRect(0, 0, 30, 15); //----- //----- ハイライト表示、actionのリセット m_action = None; // click if (m_highlightedFosFrame >= 0) { m_highlightedFosFrame = -1; viewer->update(); } if (m_highlightedMosFrame >= 0) { m_highlightedMosFrame = -1; viewer->update(); } //----- 以下、クリック位置に応じてアクションを変えていく //クリックされたフレームを取得 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e); int frame = y2index(mouseEvent->pos().y()); m_buttonPressCellIndex = frame; int currentFrame = getCurrentFrame(); //各フレーム左上からの位置 QPoint clickedPos = mouseEvent->pos() + QPoint(0, -index2y(frame)); //カレントフレームの場合、無視 if (frame == currentFrame) return false; //カレントフレームの上下でタブをクリックした場合 else if ((frame == currentFrame - 1 && backOnionTabRect.contains(clickedPos)) || (frame == currentFrame + 1 && frontOnionTabRect.contains(clickedPos))) { //ドラッグに備える m_action = ActivateMos; } //カレントフレーム以外の場合 else { //通常のOnionSkinの場合 if (onionDotRect.contains(clickedPos)) { // 既にオニオンスキンなら、オフにする bool on = !isMos(frame); //アクションが決まる m_action = on ? ActivateMos : DeactivateMos; //カレントフレームでなければ、オニオンスキンを切り替え setMos(frame, on); } //FixedOnionSkinの場合 else if (fixedOnionDotRect.contains(clickedPos)) { // Fos bool on = !isFos(frame); m_action = on ? ActivateFos : DeactivateFos; setFos(frame, on); } else return false; } viewer->update(); } //---- 上下タブのダブルクリックで表示/非表示の切り替え else if (e->type() == QEvent::MouseButtonDblClick) { QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e); if (mouseEvent->buttons() & Qt::LeftButton) { int frame = y2index(mouseEvent->pos().y()); //各フレーム左上からの位置 QPoint clickedPos = mouseEvent->pos() + QPoint(0, -index2y(frame)); //カレントフレーム int currentFrame = getCurrentFrame(); //上方向のOnionSkinタブのRect QRect backOnionTabRect(0, m_dy - 15, 30, 15); //下方向のOnionSkinタブのRect QRect frontOnionTabRect(0, 0, 30, 15); if ((currentFrame - 1 == frame && backOnionTabRect.contains(clickedPos)) || (currentFrame + 1 == frame && frontOnionTabRect.contains(clickedPos))) { enableOnionSkin(!isOnionSkinEnabled()); viewer->update(); } } else return false; } //---- else if (e->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e); int frame = y2index(mouseEvent->pos().y()); //各フレーム左上からの位置 QPoint clickedPos = mouseEvent->pos() + QPoint(0, -index2y(frame)); //カレントフレーム int currentFrame = getCurrentFrame(); //マウスボタンが押されていない場合 if (mouseEvent->buttons() == 0) { //----- それぞれのパーツの位置Rectの指定。各フレームの右上座標からのオフセットも含む。 //OnionSkinの円の左上座標のy値 int onionDotYPos = m_dy / 2 - 5; //OnionSkinの●のRect QRect onionDotRect(10, onionDotYPos, 10, 10); //FixedOnionSkinの●のRect QRect fixedOnionDotRect(0, onionDotYPos, 10, 10); //上方向のOnionSkinタブのRect QRect backOnionTabRect(0, m_dy - 15, 30, 15); //下方向のOnionSkinタブのRect QRect frontOnionTabRect(0, 0, 30, 15); //----- //----- Fixed Onion Skin の ハイライト int highlightedFrame; if (currentFrame != frame && fixedOnionDotRect.contains(clickedPos)) highlightedFrame = frame; else highlightedFrame = -1; if (highlightedFrame != m_highlightedFosFrame) { m_highlightedFosFrame = highlightedFrame; viewer->update(); } //----- //----- 通常の Onion Skin の ハイライト if (currentFrame != frame && onionDotRect.contains(clickedPos)) highlightedFrame = frame; else highlightedFrame = -1; if (highlightedFrame != m_highlightedMosFrame) { m_highlightedMosFrame = highlightedFrame; viewer->update(); } //----- //----- ツールチップの表示 if (currentFrame == frame) { viewer->setToolTip(tr("")); return false; } //Fixed Onion Skin else if (fixedOnionDotRect.contains(clickedPos)) viewer->setToolTip(tr("Click to Toggle Fixed Onion Skin")); //通常の Onion Skin else if (onionDotRect.contains(clickedPos)) viewer->setToolTip(tr("Click / Drag to Toggle Onion Skin")); //カレントフレームの上下タブ else if ((currentFrame - 1 == frame && backOnionTabRect.contains(clickedPos)) || (currentFrame + 1 == frame && frontOnionTabRect.contains(clickedPos))) viewer->setToolTip(tr("Drag to Extend Onion Skin, Double Click to Toggle All")); else { viewer->setToolTip(tr("")); return false; } } //左ボタンドラッグの場合 else if (mouseEvent->buttons() & Qt::LeftButton) { //指定されたアクションに従い、ドラッグされたフレームも同じアクションを行う // drag switch (m_action) { case MoveHead: setCurrentFrame(frame); break; case ActivateMos: setMos(frame, true); break; case DeactivateMos: setMos(frame, false); break; case ActivateFos: setFos(frame, true); break; case DeactivateFos: setFos(frame, false); break; default: return false; } viewer->update(); } else if (mouseEvent->buttons() & Qt::MidButton) return false; } else return false; return true; }
bool FrameHeadGadget::eventFilter(QObject *obj, QEvent *e) { QWidget *viewer = dynamic_cast<QWidget *>(obj); if (e->type() == QEvent::MouseButtonPress) { m_action = None; // click if (m_highlightedFosFrame >= 0) { m_highlightedFosFrame = -1; viewer->update(); } QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e); int frame = y2index(mouseEvent->pos().y()); m_buttonPressCellIndex = frame; int currentFrame = getCurrentFrame(); int x = mouseEvent->pos().x(); int y = mouseEvent->pos().y() - index2y(frame); if (x > 24 || x > 12 && frame != currentFrame) return false; if (y < 12) { #ifdef STUDENT bool isMosArea = false; #else bool isMosArea = x < 6; #endif // click nel quadratino bianco. if (isMosArea) { // Mos bool on = !isMos(frame); m_action = on ? ActivateMos : DeactivateMos; if (frame != currentFrame) setMos(frame, on); } else if (frame == currentFrame) m_action = MoveHead; else { // Fos bool on = !isFos(frame); m_action = on ? ActivateFos : DeactivateFos; setFos(frame, on); } } else { // fuori dal quadratino bianco: muovo il frame corrente m_action = MoveHead; setCurrentFrame(frame); } viewer->update(); } else if (e->type() == QEvent::MouseButtonRelease) { QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e); int frame = y2index(mouseEvent->pos().y()); int currentFrame = getCurrentFrame(); int x = mouseEvent->pos().x(); int y = mouseEvent->pos().y() - index2y(frame); if (x > 24 || x > 12 && frame != currentFrame) return false; if (mouseEvent->button() == Qt::RightButton) return false; #ifndef STUDENT if (x < 12 && y < 12 && frame == currentFrame && m_buttonPressCellIndex == frame) { enableOnionSkin(!isOnionSkinEnabled()); viewer->update(); } #endif } else if (e->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e); int frame = y2index(mouseEvent->pos().y()); int x = mouseEvent->pos().x(); int y = mouseEvent->pos().y() - index2y(frame); if (mouseEvent->buttons() == 0) { // mouse move int highlightedFosFrame = (6 <= x && x <= 12 && y < 12) ? frame : -1; if (highlightedFosFrame != m_highlightedFosFrame) { m_highlightedFosFrame = highlightedFosFrame; viewer->update(); } if (getCurrentFrame() == frame) viewer->setToolTip(tr("Current Frame")); else if (x < 7) { #ifdef STUDENT viewer->setToolTip(tr("Relative Onion Skin Toggle")); #else viewer->setToolTip(""); #endif } else if (x < 13) viewer->setToolTip(tr("Fixed Onion Skin Toggle")); else viewer->setToolTip(tr("")); } else if (mouseEvent->buttons() & Qt::LeftButton) { // drag switch (m_action) { case MoveHead: setCurrentFrame(frame); break; #ifndef STUDENT case ActivateMos: setMos(frame, true); break; #endif case DeactivateMos: setMos(frame, false); break; case ActivateFos: setFos(frame, true); break; case DeactivateFos: setFos(frame, false); break; default: return false; } viewer->update(); } else if (mouseEvent->buttons() & Qt::MidButton) return false; } else return false; return true; }
/**************************************************************************** ** ** Copyright (C) 2016 ** ** This file is generated by the Magus toolkit ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ****************************************************************************/ // Include #include "asset_curve_dialog.h" #include <QBrush> #include <QFrame> namespace Magus { //****************************************************************************/ QtCurveDialog::QtCurveDialog(const QString& iconDir, QWidget* parent) : QDialog (parent) { mIconDir = iconDir; mInnerMain = new QMainWindow(); QVBoxLayout* mainLayout = new QVBoxLayout; mButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject())); // Perform standard functions createActions(); createMenus(); createToolBars(); mScene = new QtCurveGrid(); mView = new QGraphicsView(this); mView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff ); mView->setScene(mScene); mScene->setParentView(mView); mView->setRenderHint(QPainter::Antialiasing, true); mView->setInteractive(true); mView->setMouseTracking(true); mainLayout->addWidget(mInnerMain); mainLayout->addWidget(mButtonBox); mInnerMain->setCentralWidget(mView); setMinimumWidth(CURVE_DIALOG_WIDTH); setMinimumHeight(CURVE_DIALOG_HEIGHT); setWindowTitle(QString("Curve editor")); refreshToolbarValues(); setLayout(mainLayout); } //****************************************************************************/ QtCurveDialog::~QtCurveDialog(void) { } //****************************************************************************/ void QtCurveDialog::addPoint(qreal x, qreal y) { mScene->addPoint(x, y); } //****************************************************************************/ void QtCurveDialog::addPoint(QPointF point) { mScene->addPoint(point.x(), point.y()); } //****************************************************************************/ void QtCurveDialog::setPoints(QVector<QPointF>& points) { QVectorIterator<QPointF> i(points); QPointF p; while (i.hasNext()) { p = i.next(); addPoint(p); } } //****************************************************************************/ QVector<QPointF>& QtCurveDialog::getPoints(void) { return mScene->getPoints(); } //****************************************************************************/ void QtCurveDialog::createActions(void) { mCurveFitHorToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_FIT_HORIZONTAL), QString("Fit horizontal"), this); connect(mCurveFitHorToolbarAction, SIGNAL(triggered()), this, SLOT(doCurveFitHorToolbarAction())); mCurveFitVertToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_FIT_VERTICAL), QString("Fit vertical"), this); connect(mCurveFitVertToolbarAction, SIGNAL(triggered()), this, SLOT(doCurveFitVertToolbarAction())); mCurveZoomInToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_ZOOM_IN), QString("Zoom in"), this); connect(mCurveZoomInToolbarAction, SIGNAL(triggered()), this, SLOT(doCurveZoomInToolbarAction())); mCurveZoomOutToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_ZOOM_OUT), QString("Zoom out"), this); connect(mCurveZoomOutToolbarAction, SIGNAL(triggered()), this, SLOT(doCurveZoomOutToolbarAction())); mCurveEditToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_EDIT_ON), QString("Add points"), this); connect(mCurveEditToolbarAction, SIGNAL(triggered()), this, SLOT(doCurveEditToolbarAction())); mCurveSelectToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_SELECT), QString("Select multiple points"), this); connect(mCurveSelectToolbarAction, SIGNAL(triggered()), this, SLOT(doCurveSelectToolbarAction())); mCurveMoveToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_MOVE), QString("Move the graph / move selected points"), this); connect(mCurveMoveToolbarAction, SIGNAL(triggered()), this, SLOT(doCurveMoveToolbarAction())); mPivotToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_PIVOT), QString("Reset zoom and pivot"), this); connect(mPivotToolbarAction, SIGNAL(triggered()), this, SLOT(doPivotToolbarAction())); mDeletePointsToolbarAction = new QAction(QIcon(mIconDir + CURVE_ICON_DELETE), QString("Delete all points / delete selected points"), this); connect(mDeletePointsToolbarAction, SIGNAL(triggered()), this, SLOT(doDeletePointsToolbarAction())); } //****************************************************************************/ void QtCurveDialog::createMenus(void) { } //****************************************************************************/ void QtCurveDialog::createToolBars(void) { mHToolBar = new QToolBar(); mHToolBar->setMovable(false); mInnerMain->addToolBar(Qt::TopToolBarArea, mHToolBar); mHToolBar->setMinimumHeight(64); mHToolBar->setMinimumWidth(CURVE_DIALOG_WIDTH); mHToolBar->addAction(mCurveFitHorToolbarAction); mHToolBar->addAction(mCurveFitVertToolbarAction); mHToolBar->addAction(mCurveZoomInToolbarAction); mHToolBar->addAction(mCurveZoomOutToolbarAction); mHToolBar->addAction(mCurveEditToolbarAction); mHToolBar->addAction(mCurveSelectToolbarAction); mHToolBar->addAction(mCurveMoveToolbarAction); mHToolBar->addAction(mPivotToolbarAction); // Create combobox QStringList list; list << QString("Straight line") << QString("Straight line sorted") << QString("Cubic unsorted") << QString("Cubic sorted"); mModel = new QStringListModel(list); mLineTypeCombobox = new QComboBox(); mHToolBar->addWidget(mLineTypeCombobox); mLineTypeCombobox->setModel(mModel); mLineTypeCombobox->setMaxVisibleItems(4); mLineTypeCombobox->setCurrentIndex(0); connect(mLineTypeCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int))); // Delete 'button' mHToolBar->addAction(mDeletePointsToolbarAction); // Layout x/y min- and step and decimal slider QVBoxLayout* layout = new QVBoxLayout; QHBoxLayout* xLayout = new QHBoxLayout; QHBoxLayout* yLayout = new QHBoxLayout; // X-min QHBoxLayout* xMinLayout = new QHBoxLayout; QLabel* label = new QLabel(QString("X-min:")); mXminEdit = new QLineEdit; mXminEdit->setMinimumWidth(CURVE_EDIT_WIDTH); mXminEdit->setMinimumHeight(16); connect(mXminEdit, SIGNAL(textEdited(QString)), this, SLOT(xMinEditChanged(QString))); xMinLayout->addWidget(label, 1); xMinLayout->addWidget(mXminEdit, 1); xMinLayout->addStretch(10); xLayout->addLayout(xMinLayout, 1); // X-step QHBoxLayout* xStepLayout = new QHBoxLayout; label = new QLabel(QString("X-step:")); mXstepEdit = new QLineEdit; mXstepEdit->setMinimumWidth(CURVE_EDIT_WIDTH); mXstepEdit->setMinimumHeight(16); connect(mXstepEdit, SIGNAL(textEdited(QString)), this, SLOT(xStepEditChanged(QString))); xStepLayout->addWidget(label, 1); xStepLayout->addWidget(mXstepEdit, 1); xStepLayout->addStretch(10); xLayout->addLayout(xStepLayout, 1); // X-decimals QHBoxLayout* xDecimialLayout = new QHBoxLayout; label = new QLabel(QString("X-decimals:")); mXdecimalSlider = new QSlider; mXdecimalSlider->setMinimumWidth(CURVE_SLIDER_WIDTH); mXdecimalSlider->setOrientation(Qt::Horizontal); mXdecimalSlider->setRange(0, 8); mXdecimalSlider->setTickInterval(1); connect(mXdecimalSlider, SIGNAL(valueChanged(int)), this, SLOT(sliderXValueChanged(int))); xDecimialLayout->addWidget(label, 1); xDecimialLayout->addWidget(mXdecimalSlider, 1); xLayout->addLayout(xDecimialLayout, 1); // Y-min QHBoxLayout* yMinLayout = new QHBoxLayout; label = new QLabel(QString("Y-min:")); mYminEdit = new QLineEdit; mYminEdit->setMinimumWidth(CURVE_EDIT_WIDTH); mYminEdit->setMinimumHeight(16); connect(mYminEdit, SIGNAL(textEdited(QString)), this, SLOT(yMinEditChanged(QString))); yMinLayout->addWidget(label, 1); yMinLayout->addWidget(mYminEdit, 1); yMinLayout->addStretch(10); yLayout->addLayout(yMinLayout, 1); // Y-step QHBoxLayout* yStepLayout = new QHBoxLayout; label = new QLabel(QString("Y-step:")); mYstepEdit = new QLineEdit; mYstepEdit->setMinimumWidth(CURVE_EDIT_WIDTH); mYstepEdit->setMinimumHeight(16); connect(mYstepEdit, SIGNAL(textEdited(QString)), this, SLOT(yStepEditChanged(QString))); yStepLayout->addWidget(label, 1); yStepLayout->addWidget(mYstepEdit, 1); yStepLayout->addStretch(10); yLayout->addLayout(yStepLayout, 1); // Y-decimals QHBoxLayout* yDecimialLayout = new QHBoxLayout; label = new QLabel(QString("Y-decimals:")); mYdecimalSlider = new QSlider; mYdecimalSlider->setMinimumWidth(CURVE_SLIDER_WIDTH); mYdecimalSlider->setOrientation(Qt::Horizontal); mYdecimalSlider->setRange(0, 8); mYdecimalSlider->setTickInterval(1); connect(mYdecimalSlider, SIGNAL(valueChanged(int)), this, SLOT(sliderYValueChanged(int))); yDecimialLayout->addWidget(label, 1); yDecimialLayout->addWidget(mYdecimalSlider, 1); yLayout->addLayout(yDecimialLayout, 1); // Add to toolbar QFrame* frame = new QFrame; xLayout->addStretch(1000); yLayout->addStretch(1000); layout->addLayout(xLayout, 1); layout->addLayout(yLayout, 1); layout->addStretch(1000); frame->setLayout(layout); mHToolBar->addWidget(frame); } //****************************************************************************/ void QtCurveDialog::doCurveFitHorToolbarAction(void) { mScene->fitHorizontal(); refreshToolbarValues(); } //****************************************************************************/ void QtCurveDialog::doCurveFitVertToolbarAction(void) { mScene->fitVertical(); refreshToolbarValues(); } //****************************************************************************/ void QtCurveDialog::doCurveZoomInToolbarAction(void) { mScene->zoomIn(); refreshToolbarValues(); } //****************************************************************************/ void QtCurveDialog::doCurveZoomOutToolbarAction(void) { mScene->zoomOut(); refreshToolbarValues(); } //****************************************************************************/ void QtCurveDialog::doCurveEditToolbarAction(void) { mCurveEditToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_EDIT_ON)); mCurveSelectToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_SELECT)); mCurveMoveToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_MOVE)); mScene->setMode(QtCurveGrid::EDIT); } //****************************************************************************/ void QtCurveDialog::doCurveSelectToolbarAction(void) { mCurveEditToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_EDIT)); mCurveSelectToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_SELECT_ON)); mCurveMoveToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_MOVE)); mScene->setMode(QtCurveGrid::SELECT); //mView->setDragMode(QGraphicsView::RubberBandDrag); } //****************************************************************************/ void QtCurveDialog::doCurveMoveToolbarAction(void) { mCurveEditToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_EDIT)); mCurveSelectToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_SELECT)); mCurveMoveToolbarAction->setIcon(QIcon(mIconDir + CURVE_ICON_MOVE_ON)); mScene->setMode(QtCurveGrid::MOVE); //mView->setDragMode(QGraphicsView::NoDrag); } //****************************************************************************/ void QtCurveDialog::doPivotToolbarAction(void) { // Set to default mScene->setStep(30); mScene->setXmin(0.0f); mScene->setYmin(0.0f); mScene->setXstep(0.5f); mScene->setYstep(0.5f); mScene->setDecimalX(1); mScene->setDecimalY(1); refreshToolbarValues(); } //****************************************************************************/ void QtCurveDialog::doDeletePointsToolbarAction(void) { mScene->deletePoints(); } //****************************************************************************/ void QtCurveDialog::wheelEvent (QWheelEvent* event) { // Delegate it to the scene mScene->wheelEvent(event); refreshToolbarValues(); event->accept(); } //****************************************************************************/ void QtCurveDialog::resizeEvent (QResizeEvent* event) { mScene->refresh(); event->accept(); } //****************************************************************************/ void QtCurveDialog::keyPressEvent(QKeyEvent* event) { if(event->key() == Qt::Key_Delete) { mScene->deletePoints(); } } //****************************************************************************/ void QtCurveDialog::refresh (void) { // Update the viewport QWidget* viewport = mView->viewport(); viewport->update(); }
void HoverIndex::timerEvent(QTimerEvent * event) { if (event->timerId() != timer.timerId() || items.isEmpty()) return; Items::iterator it; IndexInfo::Fades::iterator step; it = items.begin(); QWidget *w; while (it != items.end()) { if (!it.key()) { it = items.erase(it); continue; } #if QT_VERSION >= 0x040400 // below does work in general, but is... ugly?! // another way would be to map to a const widget first or perform a static_cast - ughh w = const_cast<QWidget*>(it.key().data()); #else w = const_cast<QWidget*>(&(*it.key())); #endif IndexInfo &info = it.value(); if (info.fades[In].isEmpty() && info.fades[Out].isEmpty()) { ++it; continue; } step = info.fades[In].begin(); while (step != info.fades[In].end()) { step.value() += 2; if ((uint)step.value() > (maxSteps-2)) step = info.fades[In].erase(step); else ++step; } step = info.fades[Out].begin(); while (step != info.fades[Out].end()) { step.value() -= 2; if (step.value() < 1) step = info.fades[Out].erase(step); else ++step; } w->update(); if (info.index == 0L && // nothing actually hovered info.fades[In].isEmpty() && // no fade ins info.fades[Out].isEmpty()) // no fade outs it = items.erase(it); // so remove this item else ++it; } if (items.isEmpty()) timer.stop(); }