void GridCardViewerWidget::setWaitingForTurn( bool waiting ) { if( mWaitingForTurn != waiting ) { mWaitingForTurn = waiting; updateButtonVisibility(); } };
void RoutingPluginPrivate::updateDestinationInformation() { if ( m_routingModel->route().currentSegment().isValid() ) { qreal remaining = remainingDistance(); qreal distanceLeft = nextInstructionDistance(); m_audio->update( m_routingModel->route(), distanceLeft, remaining, m_routingModel->deviatedFromRoute() ); m_nearNextInstruction = distanceLeft < thresholdDistance; QString pixmapHtml = "<img src=\":/flag.png\" /><br />"; m_widget.destinationDistanceLabel->setText( pixmapHtml + richText( fuzzyDistance( remaining ) ) ); m_widget.instructionIconLabel->setEnabled( m_nearNextInstruction ); m_widget.progressBar->setMaximum( thresholdDistance ); m_widget.progressBar->setValue( qRound( distanceLeft ) ); updateButtonVisibility(); QString pixmap = MarbleDirs::path( "bitmaps/routing_step.png" ); pixmapHtml = QString( "<img src=\"%1\" />" ).arg( pixmap ); qreal planetRadius = m_marbleWidget->model()->planet()->radius(); GeoDataCoordinates const onRoute = m_routingModel->route().positionOnRoute(); GeoDataCoordinates const ego = m_routingModel->route().position(); qreal const distanceToRoute = planetRadius * distanceSphere( ego, onRoute ); if ( !m_routingModel->route().currentSegment().isValid() ) { m_widget.instructionLabel->setText( richText( QObject::tr( "Calculate a route to get directions." ) ) ); m_widget.instructionIconLabel->setText( pixmapHtml ); } else if ( distanceToRoute > 300.0 ) { m_widget.instructionLabel->setText( richText( QObject::tr( "Route left." ) ) ); m_widget.instructionIconLabel->setText( pixmapHtml ); } else if ( !m_routingModel->route().currentSegment().nextRouteSegment().isValid() ) { m_widget.instructionLabel->setText( richText( QObject::tr( "Destination ahead." ) ) ); m_widget.instructionIconLabel->setText( pixmapHtml ); } else { pixmap = m_routingModel->route().currentSegment().nextRouteSegment().maneuver().directionPixmap(); QString const instructionText = m_routingModel->route().currentSegment().nextRouteSegment().maneuver().instructionText(); m_widget.instructionLabel->setText( richText( "%1" ).arg( instructionText ) ); pixmapHtml = QString( "<p align=\"center\"><img src=\"%1\" /><br />%2</p>" ).arg( pixmap ); m_widget.instructionIconLabel->setText( pixmapHtml.arg( richText( fuzzyDistance( distanceLeft ) ) ) ); if( remaining > 50 ) { m_routeCompleted = false; } else { if ( !m_routeCompleted ) { QString content = QObject::tr( "Arrived at destination. <a href=\"#reverse\">Calculate the way back.</a>" ); m_widget.instructionLabel->setText( richText( "%1" ).arg( content ) ); } m_routeCompleted = true; } } forceRepaint(); } }
void GridCardViewerWidget::selectedCardsUpdateHandler() { for( auto w : mCardWidgetsList ) { updateCardWidgetSelectedAppearance( w ); } updateButtonVisibility(); }
void UIGDetailsElement::paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget*) { /* Update button visibility: */ updateButtonVisibility(); /* Configure painter shape: */ configurePainterShape(pPainter, pOption, m_iCornerRadius); /* Paint decorations: */ paintDecorations(pPainter, pOption); /* Paint element info: */ paintElementInfo(pPainter, pOption); }
void RoutingPluginPrivate::toggleGuidanceMode( bool enabled ) { if( !m_marbleWidget || m_guidanceModeEnabled == enabled ) { return; } m_guidanceModeEnabled = enabled; updateButtonVisibility(); if( enabled ) { QObject::connect( m_routingModel, SIGNAL(positionChanged()), m_parent, SLOT(updateDestinationInformation()) ); } else { QObject::disconnect( m_routingModel, SIGNAL(positionChanged()), m_parent, SLOT(updateDestinationInformation()) ); } if ( enabled ) { QString const text = QObject::tr( "Starting guidance mode, please wait..." ); m_widget.instructionLabel->setText( richText( "%1" ).arg( text ) ); } if ( enabled ) { RouteRequest* request = m_marbleWidget->model()->routingManager()->routeRequest(); if ( request && request->size() > 0 ) { GeoDataCoordinates source = request->source(); if ( source.isValid() ) { GeoDataLookAt view; view.setCoordinates( source ); // By happy coincidence this equals OpenStreetMap tile level 15 view.setRange( 851.807 ); m_marbleWidget->flyTo( view ); } } } m_marbleWidget->model()->routingManager()->setGuidanceModeEnabled( enabled ); if ( enabled ) { m_routeCompleted = false; } forceRepaint(); }
void Manager::resizeEvent(TQResizeEvent*) { updateButtonVisibility(); updateTitleBuffer(); widget()->tqrepaint(); }
// Set top-level layout to show cards. // Entry conditions: // - mCardWidgetsList contains CardWidgets from previous layout (any // widgets not reused should be cleaned up) // Exit requirements: // - mCardsList must be set to the list of cards // - mCardWidgetsList must contain all CardWidgets in the layout void GridCardViewerWidget::setCards( const QList<CardDataSharedPtr>& cards ) { // No need to lay everything out again if nothing changed. if( mCardsList == cards ) return; mCardsList = cards; // // Performance gets bad if creating all new widgets from scratch, // especially when images are scaled. Instead need to extract the // widgets from the layout, then only create new stuff as needed. // // Liberate the widgets we want to retain before clearing out the layout. for( auto w : mCardWidgetsList ) { w->setParent( 0 ); } for( int col = 0; col < 3; ++col ) { mTopColButtons[col]->setParent( 0 ); mBottomColButtons[col]->setParent( 0 ); } for( int row = 0; row < 3; ++row ) { mLeftRowButtons[row]->setParent( 0 ); mRightRowButtons[row]->setParent( 0 ); } // Our grid layout will be actually deleted below by clearLayout, but // need to null out our pointer. mGridCardsLayout = nullptr; // Remove any previously created widget from the alertable set. clearAlertableSubwidgets(); // Clear out the top-level layout - we're rebuilding it here. qtutils::clearLayout( mLayout ); // Function to clean up cardwidgets in the tracking list. auto cleanupCardWidgetsListFn = [this]() { for( auto w : mCardWidgetsList ) { w->deleteLater(); } mCardWidgetsList.clear(); }; // At this point everything is cleared. Finish cleanup and exit if // there aren't exactly 9 cards in the list. if( mCardsList.size() != 9 ) { // Zero is normal, but non-zero is not. if( mCardsList.size() > 0 ) { mLogger->warn( "card list size ({}) != 9, cannot perform grid layout!", cards.size() ); } // Clean up any cardwidgets remaining in the original list. cleanupCardWidgetsListFn(); return; } // This will contain all widgets once they're created/reused. QList<CardWidget*> newCardWidgetsList; // This local function picks a matching already-created CardWidget from // our tracking list to speed up the overall "setCards" operation which happens // on every sort, categorize, etc. auto takeWidgetFromCardWidgetsList = [this]( const CardDataSharedPtr& cardDataSharedPtr ) -> CardWidget* { for( int i = 0; i < mCardWidgetsList.count(); ++i ) { CardWidget* w = mCardWidgetsList[i]; if( w->getCardData() == cardDataSharedPtr ) { mLogger->debug( "reusing CardWidget for name={} muid={}", cardDataSharedPtr->getName(), cardDataSharedPtr->getMultiverseId() ); mCardWidgetsList.takeAt( i ); w->resetTraits(); updateCardWidgetSelectedAppearance( w ); return w; } } return nullptr; }; // This local function creates and connects a CardWidget. auto createCardWidget = [this]( const CardDataSharedPtr& cardDataSharedPtr ) -> CardWidget* { mLogger->debug( "creating CardWidget name={} muid={}", cardDataSharedPtr->getName(), cardDataSharedPtr->getMultiverseId() ); QString card = QString::fromStdString( cardDataSharedPtr->getName() ); CardWidget* cardWidget = new CardWidget( cardDataSharedPtr, mImageLoaderFactory, QSize( 223, 310 ), mLoggingConfig.createChildConfig( "cardwidget" ) ); cardWidget->setZoomFactor( mZoomFactor ); updateCardWidgetSelectedAppearance( cardWidget ); cardWidget->loadImage(); connect(cardWidget, SIGNAL(preselectRequested()), this, SLOT(handleCardPreselectRequested())); connect(cardWidget, SIGNAL(selectRequested()), this, SLOT(handleCardSelectRequested())); connect(cardWidget, SIGNAL(moveRequested()), this, SLOT(handleCardMoveRequested())); cardWidget->setContextMenuPolicy( Qt::CustomContextMenu ); connect(cardWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(handleCardContextMenu(const QPoint&))); return cardWidget; }; // // Lay out the cards and buttons in a grid. // // This widget shouldn't be needed but Qt gets confused when the // layout is added directly. Having a widget own it seems to help. QWidget* gridCardsLayoutWidget = new QWidget(); // The widget needs to turn red when the alert is active. addAlertableSubwidget( gridCardsLayoutWidget ); mGridCardsLayout = new QGridLayout( gridCardsLayoutWidget ); // Center the gridlayout using a QHBoxLayout and add to parent layout // before adding widgets as mentioned in Qt docs. QHBoxLayout* alignmentLayout = new QHBoxLayout(); alignmentLayout->addStretch(); alignmentLayout->addWidget( gridCardsLayoutWidget ); alignmentLayout->addStretch(); mLayout->addLayout( alignmentLayout ); // Lay out column buttons. for( int col = 0; col < 3; ++col ) { mGridCardsLayout->addWidget( mTopColButtons[col], 0, 1 + col, Qt::AlignCenter ); mGridCardsLayout->addWidget( mBottomColButtons[col], 4, 1 + col, Qt::AlignCenter ); } // Lay out row buttons. for( int row = 0; row < 3; ++row ) { mGridCardsLayout->addWidget( mLeftRowButtons[row], 1 + row, 0, Qt::AlignCenter ); mGridCardsLayout->addWidget( mRightRowButtons[row], 1 + row, 4, Qt::AlignCenter ); } updateButtonVisibility(); // Create card widgets and add to layout. for( int i = 0; i < 9; ++i ) { auto cardDataSharedPtr = mCardsList[i]; // Look for an existing card widget that matches our card data, // and extract it from the list if found. CardWidget* cardWidget = nullptr; cardWidget = takeWidgetFromCardWidgetsList( cardDataSharedPtr ); if( !cardWidget ) { // The widget doesn't exist. Create it. cardWidget = createCardWidget( cardDataSharedPtr ); } mGridCardsLayout->addWidget( cardWidget, 1+ i/3, 1 + i%3 ); newCardWidgetsList.push_back( cardWidget ); } if( mFooterSpacing > 0 ) mLayout->addSpacing( mFooterSpacing ); // This keeps everything pushed nicely to the top of the main area. mLayout->addStretch(); // Clean up any cardwidgets remaining in the original list. cleanupCardWidgetsListFn(); // Old is new. mCardWidgetsList = newCardWidgetsList; }