BugzillaModule::BugzillaModule() { ADD_INTERFACE_IMPL(BugzillaNoteAddin); ADD_INTERFACE_IMPL(BugzillaPreferencesFactory); enabled(false); }
void QgsDecorationNorthArrow::render( const QgsMapSettings &mapSettings, QgsRenderContext &context ) { if ( !enabled() ) return; double maxLength = mSize * mapSettings.outputDpi() / 25.4; QSvgRenderer svg; const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( svgPath(), maxLength, mColor, mOutlineColor, 1.0, 1.0 ); svg.load( svgContent ); if ( svg.isValid() ) { QSize size( maxLength, maxLength ); QRectF viewBox = svg.viewBoxF(); if ( viewBox.height() > viewBox.width() ) { size.setWidth( maxLength * viewBox.width() / viewBox.height() ); } else { size.setHeight( maxLength * viewBox.height() / viewBox.width() ); } double centerXDouble = size.width() / 2.0; double centerYDouble = size.height() / 2.0; //save the current canvas rotation context.painter()->save(); // //work out how to shift the image so that it rotates // properly about its center //(x cos a + y sin a - x, -x sin a + y cos a - y) // // could move this call to somewhere else so that it is only // called when the projection or map extent changes if ( mAutomatic ) { try { mRotationInt = QgsBearingUtils:: bearingTrueNorth( mapSettings.destinationCrs(), mapSettings.transformContext(), context.extent().center() ); } catch ( QgsException & ) { mRotationInt = 0.0; } mRotationInt += mapSettings.rotation(); } double radiansDouble = mRotationInt * M_PI / 180.0; int xShift = static_cast<int>( ( ( centerXDouble * std::cos( radiansDouble ) ) + ( centerYDouble * std::sin( radiansDouble ) ) ) - centerXDouble ); int yShift = static_cast<int>( ( ( -centerXDouble * std::sin( radiansDouble ) ) + ( centerYDouble * std::cos( radiansDouble ) ) ) - centerYDouble ); // need width/height of paint device int deviceHeight = context.painter()->device()->height(); int deviceWidth = context.painter()->device()->width(); // Set margin according to selected units int xOffset = 0; int yOffset = 0; switch ( mMarginUnit ) { case QgsUnitTypes::RenderMillimeters: { int pixelsInchX = context.painter()->device()->logicalDpiX(); int pixelsInchY = context.painter()->device()->logicalDpiY(); xOffset = pixelsInchX * INCHES_TO_MM * mMarginHorizontal; yOffset = pixelsInchY * INCHES_TO_MM * mMarginVertical; break; } case QgsUnitTypes::RenderPixels: xOffset = mMarginHorizontal - 5; // Minus 5 to shift tight into corner yOffset = mMarginVertical - 5; break; case QgsUnitTypes::RenderPercentage: xOffset = ( ( deviceWidth - size.width() ) / 100. ) * mMarginHorizontal; yOffset = ( ( deviceHeight - size.width() ) / 100. ) * mMarginVertical; break; case QgsUnitTypes::RenderMapUnits: case QgsUnitTypes::RenderPoints: case QgsUnitTypes::RenderInches: case QgsUnitTypes::RenderUnknownUnit: case QgsUnitTypes::RenderMetersInMapUnits: break; } //Determine placement of label from form combo box switch ( mPlacement ) { case BottomLeft: context.painter()->translate( xOffset, deviceHeight - yOffset - maxLength + ( maxLength - size.height() ) / 2 ); break; case TopLeft: context.painter()->translate( xOffset, yOffset ); break; case TopRight: context.painter()->translate( deviceWidth - xOffset - maxLength + ( maxLength - size.width() ) / 2, yOffset ); break; case BottomRight: context.painter()->translate( deviceWidth - xOffset - maxLength + ( maxLength - size.width() ) / 2, deviceHeight - yOffset - maxLength + ( maxLength - size.height() ) / 2 ); break; } //rotate the canvas by the north arrow rotation amount context.painter()->rotate( mRotationInt ); //Now we can actually do the drawing, and draw a smooth north arrow even when rotated context.painter()->translate( xShift, yShift ); svg.render( context.painter(), QRectF( 0, 0, size.width(), size.height() ) ); //unrotate the canvas again context.painter()->restore(); } }
void setCount(const Counter counter) { if (enabled()) { mCount = counter; mHasCount = true; } }
void LayerThicknessVariation::updateEnabled() { emit enabledChanged(enabled()); }
void QgsDecorationCopyright::render( QPainter * theQPainter ) { //Large IF statement to enable/disable copyright label if ( enabled() ) { // need width/height of paint device int myHeight = theQPainter->device()->height(); int myWidth = theQPainter->device()->width(); QTextDocument text; text.setDefaultFont( mQFont ); // To set the text color in a QTextDocument we use a CSS style QString style = "<style type=\"text/css\"> p {color: " + mLabelQColor.name() + "}</style>"; text.setHtml( style + "<p>" + mLabelQString + "</p>" ); QSizeF size = text.size(); float myXOffset( 0 ), myYOffset( 0 ); // Set margin according to selected units switch ( mMarginUnit ) { case QgsUnitTypes::RenderMillimeters: { int myPixelsInchX = theQPainter->device()->logicalDpiX(); int myPixelsInchY = theQPainter->device()->logicalDpiY(); myXOffset = myPixelsInchX * INCHES_TO_MM * mMarginHorizontal; myYOffset = myPixelsInchY * INCHES_TO_MM * mMarginVertical; break; } case QgsUnitTypes::RenderPixels: myXOffset = mMarginHorizontal; myYOffset = mMarginVertical; break; case QgsUnitTypes::RenderPercentage: myXOffset = (( myWidth - size.width() ) / 100. ) * mMarginHorizontal; myYOffset = (( myHeight - size.height() ) / 100. ) * mMarginVertical; break; default: // Use default of top left break; } //Determine placement of label from form combo box switch ( mPlacement ) { case BottomLeft: // Bottom Left. myXOffset is set above myYOffset = myHeight - myYOffset - size.height(); break; case TopLeft: // Top left. Already setup above break; case TopRight: // Top Right. myYOffset is set above myXOffset = myWidth - myXOffset - size.width(); break; case BottomRight: // Bottom Right //Define bottom right hand corner start point myYOffset = myHeight - myYOffset - size.height(); myXOffset = myWidth - myXOffset - size.width(); break; default: QgsDebugMsg( QString( "Unknown placement index of %1" ).arg( static_cast<int>( mPlacement ) ) ); } //Paint label to canvas QMatrix worldMatrix = theQPainter->worldMatrix(); theQPainter->translate( myXOffset, myYOffset ); text.drawContents( theQPainter ); // Put things back how they were theQPainter->setWorldMatrix( worldMatrix ); } }
bool is_enabled() const { data::read enabled(m_enabled); return enabled.use(); }
~binding () { kassert (!enabled ()); }
void on_create( const value_type& v ) { if( !enabled() ) return; auto& head = _stack.back(); head.new_ids.insert( v.id ); }
void OfflineCollectorPlugin::update ( int command, ClassAd &ad ) { dprintf ( D_FULLDEBUG, "In OfflineCollectorPlugin::update ( %d )\n", command ); /* bail out if the plug-in is not enabled */ if ( !enabled () ) { return; } /* make sure the command is relevant to us */ if ( UPDATE_STARTD_AD_WITH_ACK != command && UPDATE_STARTD_AD != command && MERGE_STARTD_AD != command ) { return; } MyString s; const char *key = makeOfflineKey(ad,s); if (!key) return; /* report whether this ad is "off-line" or not and update the ad accordingly. */ int offline = FALSE, lifetime = 0; bool offline_explicit = false; if( ad.EvalBool( ATTR_OFFLINE, NULL, offline ) ) { offline_explicit = true; } if ( MERGE_STARTD_AD == command ) { mergeClassAd( ad, key ); return; } // Rewrite the ad if it is going offline if ( UPDATE_STARTD_AD_WITH_ACK == command && !offline_explicit ) { /* set the off-line state of the machine */ offline = TRUE; /* get the off-line expiry time (default to INT_MAX) */ lifetime = param_integer ( "OFFLINE_EXPIRE_ADS_AFTER", INT_MAX ); /* reset any values in the ad that may interfere with a match in the future */ /* Reset Condor state */ ad.Assign ( ATTR_STATE, state_to_string ( unclaimed_state ) ); ad.Assign ( ATTR_ACTIVITY, activity_to_string ( idle_act ) ); ad.Assign ( ATTR_ENTERED_CURRENT_STATE, 0 ); ad.Assign ( ATTR_ENTERED_CURRENT_ACTIVITY, 0 ); /* Set the heart-beat time */ int now = static_cast<int> ( time ( NULL ) ); ad.Assign ( ATTR_MY_CURRENT_TIME, now ); ad.Assign ( ATTR_LAST_HEARD_FROM, now ); /* Reset machine load */ ad.Assign ( ATTR_LOAD_AVG, 0.0 ); ad.Assign ( ATTR_CONDOR_LOAD_AVG, 0.0 ); ad.Assign ( ATTR_TOTAL_LOAD_AVG, 0.0 ); ad.Assign ( ATTR_TOTAL_CONDOR_LOAD_AVG, 0.0 ); /* Reset CPU load */ ad.Assign ( ATTR_CPU_IS_BUSY, false ); ad.Assign ( ATTR_CPU_BUSY_TIME, 0 ); /* Reset keyboard and mouse times */ ad.Assign ( ATTR_KEYBOARD_IDLE, INT_MAX ); ad.Assign ( ATTR_CONSOLE_IDLE, INT_MAX ); /* any others? */ dprintf ( D_FULLDEBUG, "Machine ad lifetime: %d\n", lifetime ); /* record the new values as specified above */ ad.Assign ( ATTR_OFFLINE, (bool)offline ); if ( lifetime > 0 ) { ad.Assign ( ATTR_CLASSAD_LIFETIME, lifetime ); } } /* if it is off-line then add it to the list; otherwise, remove it. */ if ( offline > 0 ) { persistentStoreAd(key,ad); } else { persistentRemoveAd(key); } }
/** * This method works similar to git squash, it merges the change set from the two most * recent revision numbers into one revision number (reducing the head revision number) * * This method does not change the state of the index, only the state of the undo buffer. */ void squash() { if( !enabled() ) return; if( _stack.size() == 1 ) { _stack.pop_front(); return; } auto& state = _stack.back(); auto& prev_state = _stack[_stack.size()-2]; // An object's relationship to a state can be: // in new_ids : new // in old_values (was=X) : upd(was=X) // in removed (was=X) : del(was=X) // not in any of above : nop // // When merging A=prev_state and B=state we have a 4x4 matrix of all possibilities: // // |--------------------- B ----------------------| // // +------------+------------+------------+------------+ // | new | upd(was=Y) | del(was=Y) | nop | // +------------+------------+------------+------------+------------+ // / | new | N/A | new A| nop C| new A| // | +------------+------------+------------+------------+------------+ // | | upd(was=X) | N/A | upd(was=X)A| del(was=X)C| upd(was=X)A| // A +------------+------------+------------+------------+------------+ // | | del(was=X) | N/A | N/A | N/A | del(was=X)A| // | +------------+------------+------------+------------+------------+ // \ | nop | new B| upd(was=Y)B| del(was=Y)B| nop AB| // +------------+------------+------------+------------+------------+ // // Each entry was composed by labelling what should occur in the given case. // // Type A means the composition of states contains the same entry as the first of the two merged states for that object. // Type B means the composition of states contains the same entry as the second of the two merged states for that object. // Type C means the composition of states contains an entry different from either of the merged states for that object. // Type N/A means the composition of states violates causal timing. // Type AB means both type A and type B simultaneously. // // The merge() operation is defined as modifying prev_state in-place to be the state object which represents the composition of // state A and B. // // Type A (and AB) can be implemented as a no-op; prev_state already contains the correct value for the merged state. // Type B (and AB) can be implemented by copying from state to prev_state. // Type C needs special case-by-case logic. // Type N/A can be ignored or assert(false) as it can only occur if prev_state and state have illegal values // (a serious logic error which should never happen). // // We can only be outside type A/AB (the nop path) if B is not nop, so it suffices to iterate through B's three containers. for( const auto& item : state.old_values ) { if( prev_state.new_ids.find( item.second.id ) != prev_state.new_ids.end() ) { // new+upd -> new, type A continue; } if( prev_state.old_values.find( item.second.id ) != prev_state.old_values.end() ) { // upd(was=X) + upd(was=Y) -> upd(was=X), type A continue; } // del+upd -> N/A assert( prev_state.removed_values.find(item.second.id) == prev_state.removed_values.end() ); // nop+upd(was=Y) -> upd(was=Y), type B prev_state.old_values.emplace( std::move(item) ); } // *+new, but we assume the N/A cases don't happen, leaving type B nop+new -> new for( auto id : state.new_ids ) prev_state.new_ids.insert(id); // *+del for( auto& obj : state.removed_values ) { if( prev_state.new_ids.find(obj.second.id) != prev_state.new_ids.end() ) { // new + del -> nop (type C) prev_state.new_ids.erase(obj.second.id); continue; } auto it = prev_state.old_values.find(obj.second.id); if( it != prev_state.old_values.end() ) { // upd(was=X) + del(was=Y) -> del(was=X) prev_state.removed_values.emplace( std::move(*it) ); prev_state.old_values.erase(obj.second.id); continue; } // del + del -> N/A assert( prev_state.removed_values.find( obj.second.id ) == prev_state.removed_values.end() ); // nop + del(was=Y) -> del(was=Y) prev_state.removed_values.emplace( std::move(obj) ); //[obj.second->id] = std::move(obj.second); } _stack.pop_back(); --_revision; }
/** * Unwinds all undo states */ void undo_all() { while( enabled() ) undo(); }
void log(const std::string& tableName, const StructuredLogEntry& cols) { if (enabled()) { s_impl(tableName, cols); } }
bool coinflip(uint32_t rate) { return enabled() && rate > 0 && folly::Random::rand32(rate) == 0; }
void Download::setEnabled(bool e) { m_enabled = e; emit enabled(e); }
//___________________________________________________________________ bool LabelData::eventFilter( QObject* object, QEvent* event ) { if ( object != target_.data() ) return TransitionData::eventFilter( object, event ); switch ( event->type() ) { case QEvent::Show: /* at show event, on set the old text to current to avoid animate the "first" paint event. text mnemonic is always removed to avoid triggering the animation when only the latter is changed */ text_ = target_.data()->text().remove( '&' ); break; case QEvent::Paint: { if ( enabled() && target_ ) { // remove showMnemonic from text before comparing QString text( target_.data()->text().remove( '&' ) ); if ( text == text_ ) { if ( transition().data()->isAnimated() && TransitionWidget::paintEnabled() ) return true; else break; } // update text and pixmap text_ = text; if ( !(transition() && target_.data()->isVisible() ) ) break; if ( transition().data()->isAnimated() ) { transition().data()->endAnimation(); } // check whether animations are locked if ( isLocked() ) { // hide transition widget transition().data()->hide(); // restart the lock timer // and abort transition lockAnimations(); break; } // restart the lock timer // and prepare transition lockAnimations(); initializeAnimation(); timer_.start( 0, this ); if ( !transition().data()->startPixmap().isNull() && TransitionWidget::paintEnabled() ) { // show the transition widget // and disable this event painting transition().data()->show(); transition().data()->raise(); return true; } else { // hide transition widget and abort transition transition().data()->hide(); break; } } else if ( transition().data()->isAnimated() && TransitionWidget::paintEnabled() ) { // disable painting when transition is running // since label is obscured by transition widget return true; } else break; } default: break; } return TransitionData::eventFilter( object, event ); }
bool OfflineCollectorPlugin::expire ( ClassAd &ad ) { classad::Value result; bool val; dprintf ( D_FULLDEBUG, "In OfflineCollectorPlugin::expire()\n" ); /* bail out if the plug-in is not enabled, or if no ABSENT_REQUIREMENTS have been defined */ if ( !enabled() || !AbsentReq ) { return false; // return false tells collector to delete this ad } /* for now, if the ad is of any type other than a startd ad, bail out. currently absent ads only supported for ads of type Machine, because our offline storage assumes that. */ if ( strcmp(GetMyTypeName(ad),STARTD_ADTYPE) ) { return false; // return false tells collector to delete this ad } /* The ad may be a STARTD_PVT_ADTYPE, even though GetMyTypeName() claims it is a STARTD_ADTYPE. Sigh. This is because the startd sends private ads w/ the wrong type, because the query object queries private ads w/ the wrong type. If I were to fix the startd to label private ads with the proper type, an incompatibility between startd/negotiator would have to be dealt with. So here we try to distinguish if this ad is really a STARTD_PVT_ADTYPE by seeing if a Capability attr is present and a State attr is not present. */ if ( ad.Lookup(ATTR_CAPABILITY) && !ad.Lookup(ATTR_STATE) ) { // looks like a private ad, we don't want to store these return false; // return false tells collector to delete this ad } /* If the ad is alraedy has ABSENT=True and it is expiring, then let it be deleted as in this case it already sat around absent for the absent lifetime. */ bool already_absent = false; ad.LookupBool(ATTR_ABSENT,already_absent); if (already_absent) { MyString s; const char *key = makeOfflineKey(ad,s); if (key) { persistentRemoveAd(key); } return false; // return false tells collector to delete this ad } /* Test is ad against the absent requirements expression, and mark the ad absent if true */ if (EvalExprTree(AbsentReq,&ad,NULL,result) && result.IsBooleanValue(val) && val) { int lifetime, timestamp; lifetime = param_integer ( "ABSENT_EXPIRE_ADS_AFTER", 60 * 60 * 24 * 30 ); // default expire absent ads in a month if ( lifetime == 0 ) lifetime = INT_MAX; // 0 means forever ad.Assign ( ATTR_ABSENT, true ); ad.Assign ( ATTR_CLASSAD_LIFETIME, lifetime ); timestamp = time(NULL); ad.Assign(ATTR_LAST_HEARD_FROM, timestamp); ad.Assign ( ATTR_MY_CURRENT_TIME, timestamp ); persistentStoreAd(NULL,ad); // if we marked this ad as absent, we want to keep it in the collector return true; // return true tells the collector to KEEP this ad } return false; // return false tells collector to delete this ad }
// Return commands to restore this breakpoint, using the dummy number // NR. If AS_DUMMY is set, delete the breakpoint immediately in order // to increase the breakpoint number. If ADDR is set, use ADDR as // (fake) address. If COND is set, use COND as (fake) condition. // Return true iff successful. bool BreakPoint::get_state(std::ostream& os, int nr, bool as_dummy, string pos, string cond) { if (pos.empty()) { if (line_nr() > 0) pos = file_name() + ":" + itostring(line_nr()); else pos = string('*') + address(); } if (cond == char(-1)) cond = real_condition(); const string num = "@" + itostring(nr) + "@"; switch (gdb->type()) { case BASH: case GDB: case MAKE: case PYDB: case DBG: { switch (type()) { case BREAKPOINT: { switch (dispo()) { case BPKEEP: case BPDIS: os << "break " << pos << "\n"; break; case BPDEL: os << "tbreak " << pos << "\n"; break; } break; } case WATCHPOINT: { os << gdb->watch_command(expr(), watch_mode()) << "\n"; break; } case TRACEPOINT: case ACTIONPOINT: { // Not handled - FIXME break; } } if (!as_dummy) { // Extra infos if (!enabled() && gdb->has_disable_command()) os << gdb->disable_command(num) << "\n"; int ignore = ignore_count(); if (ignore > 0 && gdb->has_ignore_command()) os << gdb->ignore_command(num, ignore) << "\n"; if (!cond.empty() && gdb->has_condition_command()) os << gdb->condition_command(num, cond) << "\n"; if (commands().size() != 0) { os << "commands " << num << "\n"; for (int i = 0; i < commands().size(); i++) os << commands()[i] << "\n"; os << "end\n"; } } break; } case DBX: { string cond_suffix = ""; if (!cond.empty()) { if (gdb->has_handler_command()) cond_suffix = " -if " + cond; else cond_suffix = " if " + cond; } switch (type()) { case BREAKPOINT: if (!func().empty()) { os << "stop in " << func() << "\n"; } else if (pos.contains('*', 0)) { os << "stop at " << pos.after('*') << cond_suffix << '\n'; } else { os << "file " << pos.before(':') << "\n"; os << "stop at " << pos.after(':') << cond_suffix << "\n"; } break; case WATCHPOINT: os << "stop " << expr() << cond_suffix << '\n'; break; case TRACEPOINT: case ACTIONPOINT: { // Not handled - FIXME break; } } if (!as_dummy) { // Extra infos if (!enabled() && gdb->has_disable_command()) os << gdb->disable_command(num) << "\n"; int ignore = ignore_count(); if (ignore > 0 && gdb->has_ignore_command()) os << gdb->ignore_command(num, ignore) << "\n"; } break; } case JDB: { os << "stop at " << pos << "\n"; break; } case XDB: { string cond_suffix; if (!cond.empty() && !gdb->has_condition_command()) cond_suffix = " {if " + cond + " {} {Q;c}}"; if (pos.contains('*', 0)) os << "ba " << pos.after('*') << cond_suffix << '\n'; else os << "b " << pos << cond_suffix << "\n"; if (!as_dummy) { // Extra infos if (!enabled() && gdb->has_disable_command()) os << gdb->disable_command(num) << "\n"; int ignore = ignore_count(); if (ignore > 0 && gdb->has_ignore_command()) os << gdb->ignore_command(num, ignore) << "\n"; } break; } case PERL: { string cond_suffix; if (!cond.empty()) cond_suffix = " " + cond; os << "f " << pos.before(':') << "\n"; if (type() == BREAKPOINT) os << "b " << pos.after(':') << cond_suffix << "\n"; if (commands().size() != 0) { os << "a " << pos.after(':') << " "; for (int i = 0; i < commands().size(); i++) os << commands()[i] << ";"; os << "\n"; } break; } } if (as_dummy && gdb->has_delete_command()) { // Delete the breakpoint just created os << gdb->delete_command(num) << "\n"; } return true; }
void LightComponent::onDraw(render::RenderQueue *ops) { if (enabled()) ops->lights.push_back(this); }
// Construct with specific option values. linger(bool e, int t) { enabled(e); timeout BOOST_PREVENT_MACRO_SUBSTITUTION(t); }
//____________________________________________________________ bool SplitterEngine::registerWidget( QWidget* widget ) { if( !widget ) return false; if( !data_.contains( widget ) ) { data_.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); } // connect destruction signal connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection ); return true; }
//____________________________________________________________ bool HeaderViewEngine::registerWidget( QWidget* widget ) { if( !widget ) return false; // create new data class if( !data_.contains( widget ) ) data_.insert( widget, new HeaderViewData( this, widget, duration() ), enabled() ); // connect destruction signal connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection ); return true; }
const SDL_Color& label::get_color() const { return (enabled()) ? color_ : font::DISABLED_COLOR; }
void InspectorDebuggerAgent::restore() { if (enabled()) enable(); }
void InspectorProfilerAgent::enable(ErrorString*) { if (enabled()) return; enable(false); }
void QgsDecorationScaleBar::render( QPainter * theQPainter ) { QgsMapCanvas* canvas = QgisApp::instance()->mapCanvas(); int myBufferSize = 1; //softcode this later //Get canvas dimensions int myCanvasHeight = theQPainter->device()->height(); int myCanvasWidth = theQPainter->device()->width(); //Get map units per pixel. This can be negative at times (to do with //projections) and that just confuses the rest of the code in this //function, so force to a positive number. double myMapUnitsPerPixelDouble = qAbs( canvas->mapUnitsPerPixel() ); // Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze int myLayerCount = canvas->layerCount(); if ( !myLayerCount || !myCanvasWidth || !myMapUnitsPerPixelDouble ) return; //Large if statement which determines whether to render the scale bar if ( enabled() ) { // Hard coded sizes int myMajorTickSize = 8; int myTextOffsetX = 3; double myActualSize = mPreferredSize; int myMargin = 20; //Calculate size of scale bar for preferred number of map units double myScaleBarWidth = mPreferredSize / myMapUnitsPerPixelDouble; //If scale bar is very small reset to 1/4 of the canvas wide if ( myScaleBarWidth < 30 ) { myScaleBarWidth = myCanvasWidth / 4; // pixels myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble; // map units }; //if scale bar is more than half the canvas wide keep halving until not while ( myScaleBarWidth > myCanvasWidth / 3 ) { myScaleBarWidth = myScaleBarWidth / 3; }; myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble; // Work out the exponent for the number - e.g, 1234 will give 3, // and .001234 will give -3 double myPowerOf10 = floor( log10( myActualSize ) ); // snap to integer < 10 times power of 10 if ( mSnapping ) { double scaler = pow( 10.0, myPowerOf10 ); myActualSize = round( myActualSize / scaler ) * scaler; myScaleBarWidth = myActualSize / myMapUnitsPerPixelDouble; } //Get type of map units and set scale bar unit label text QGis::UnitType myMapUnits = canvas->mapUnits(); QString myScaleBarUnitLabel; switch ( myMapUnits ) { case QGis::Meters: if ( myActualSize > 1000.0 ) { myScaleBarUnitLabel = tr( " km" ); myActualSize = myActualSize / 1000; } else if ( myActualSize < 0.01 ) { myScaleBarUnitLabel = tr( " mm" ); myActualSize = myActualSize * 1000; } else if ( myActualSize < 0.1 ) { myScaleBarUnitLabel = tr( " cm" ); myActualSize = myActualSize * 100; } else myScaleBarUnitLabel = tr( " m" ); break; case QGis::Feet: if ( myActualSize > 5280.0 ) //5280 feet to the mile { myScaleBarUnitLabel = tr( " miles" ); // Adjust scale bar width to get even numbers myActualSize = myActualSize / 5000; myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000; } else if ( myActualSize == 5280.0 ) //5280 feet to the mile { myScaleBarUnitLabel = tr( " mile" ); // Adjust scale bar width to get even numbers myActualSize = myActualSize / 5000; myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000; } else if ( myActualSize < 1 ) { myScaleBarUnitLabel = tr( " inches" ); myActualSize = myActualSize * 10; myScaleBarWidth = ( myScaleBarWidth * 10 ) / 12; } else if ( myActualSize == 1.0 ) { myScaleBarUnitLabel = tr( " foot" ); } else { myScaleBarUnitLabel = tr( " feet" ); } break; case QGis::Degrees: if ( myActualSize == 1.0 ) myScaleBarUnitLabel = tr( " degree" ); else myScaleBarUnitLabel = tr( " degrees" ); break; case QGis::UnknownUnit: myScaleBarUnitLabel = tr( " unknown" ); default: QgsDebugMsg( QString( "Error: not picked up map units - actual value = %1" ).arg( myMapUnits ) ); }; //Set font and calculate width of unit label int myFontSize = 10; //we use this later for buffering QFont myFont( "helvetica", myFontSize ); theQPainter->setFont( myFont ); QFontMetrics myFontMetrics( myFont ); double myFontWidth = myFontMetrics.width( myScaleBarUnitLabel ); double myFontHeight = myFontMetrics.height(); //Set the maximum label QString myScaleBarMaxLabel = QLocale::system().toString( myActualSize ); //Calculate total width of scale bar and label double myTotalScaleBarWidth = myScaleBarWidth + myFontWidth; //determine the origin of scale bar depending on placement selected int myOriginX = myMargin; int myOriginY = myMargin; switch ( mPlacementIndex ) { case 0: // Bottom Left myOriginX = myMargin; myOriginY = myCanvasHeight - myMargin; break; case 1: // Top Left myOriginX = myMargin; myOriginY = myMargin; break; case 2: // Top Right myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin; myOriginY = myMargin; break; case 3: // Bottom Right myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin; myOriginY = myCanvasHeight - myMargin; break; default: QgsDebugMsg( "Unable to determine where to put scale bar so defaulting to top left" ); } //Set pen to draw with QPen myForegroundPen( mColor, 2 ); QPen myBackgroundPen( Qt::white, 4 ); //Cast myScaleBarWidth to int for drawing int myScaleBarWidthInt = ( int ) myScaleBarWidth; //Create array of vertices for scale bar depending on style switch ( mStyleIndex ) { case 0: // Tick Down { QPolygon myTickDownArray( 4 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myTickDownArray.putPoints( 0, 4, myOriginX , ( myOriginY + myMajorTickSize ) , myOriginX , myOriginY , ( myScaleBarWidthInt + myOriginX ), myOriginY , ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ) ); theQPainter->drawPolyline( myTickDownArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); myTickDownArray.putPoints( 0, 4, myOriginX , ( myOriginY + myMajorTickSize ) , myOriginX , myOriginY , ( myScaleBarWidthInt + myOriginX ), myOriginY , ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ) ); theQPainter->drawPolyline( myTickDownArray ); break; } case 1: // tick up { QPolygon myTickUpArray( 4 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myTickUpArray.putPoints( 0, 4, myOriginX , myOriginY , myOriginX , myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY ); theQPainter->drawPolyline( myTickUpArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); myTickUpArray.putPoints( 0, 4, myOriginX , myOriginY , myOriginX , myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY ); theQPainter->drawPolyline( myTickUpArray ); break; } case 2: // Bar { QPolygon myBarArray( 2 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myBarArray.putPoints( 0, 2, myOriginX , ( myOriginY + ( myMajorTickSize / 2 ) ), ( myScaleBarWidthInt + myOriginX ), ( myOriginY + ( myMajorTickSize / 2 ) ) ); theQPainter->drawPolyline( myBarArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); myBarArray.putPoints( 0, 2, myOriginX , ( myOriginY + ( myMajorTickSize / 2 ) ), ( myScaleBarWidthInt + myOriginX ), ( myOriginY + ( myMajorTickSize / 2 ) ) ); theQPainter->drawPolyline( myBarArray ); break; } case 3: // box { // Want square corners for a box myBackgroundPen.setJoinStyle( Qt::MiterJoin ); myForegroundPen.setJoinStyle( Qt::MiterJoin ); QPolygon myBoxArray( 5 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myBoxArray.putPoints( 0, 5, myOriginX , myOriginY, ( myScaleBarWidthInt + myOriginX ), myOriginY, ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ), myOriginX , ( myOriginY + myMajorTickSize ), myOriginX , myOriginY ); theQPainter->drawPolyline( myBoxArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); theQPainter->setBrush( QBrush( mColor, Qt::SolidPattern ) ); int midPointX = myScaleBarWidthInt / 2 + myOriginX; myBoxArray.putPoints( 0, 5, myOriginX , myOriginY, midPointX, myOriginY, midPointX, ( myOriginY + myMajorTickSize ), myOriginX , ( myOriginY + myMajorTickSize ), myOriginX , myOriginY ); theQPainter->drawPolygon( myBoxArray ); theQPainter->setBrush( Qt::NoBrush ); myBoxArray.putPoints( 0, 5, midPointX , myOriginY, ( myScaleBarWidthInt + myOriginX ), myOriginY, ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ), midPointX , ( myOriginY + myMajorTickSize ), midPointX , myOriginY ); theQPainter->drawPolygon( myBoxArray ); break; } default: QgsDebugMsg( "Unknown style" ); } //Do actual drawing of scale bar // //Do drawing of scale bar text // QColor myBackColor = Qt::white; QColor myForeColor = Qt::black; //Draw the minimum label buffer theQPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( "0" ); myFontHeight = myFontMetrics.height(); for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { theQPainter->drawText( int( i + ( myOriginX - ( myFontWidth / 2 ) ) ), int( j + ( myOriginY - ( myFontHeight / 4 ) ) ), "0" ); } } //Draw minimum label theQPainter->setPen( myForeColor ); theQPainter->drawText( int( myOriginX - ( myFontWidth / 2 ) ), int( myOriginY - ( myFontHeight / 4 ) ), "0" ); // //Draw maximum label // theQPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( myScaleBarMaxLabel ); myFontHeight = myFontMetrics.height(); //first the buffer for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { theQPainter->drawText( int( i + ( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ) ), int( j + ( myOriginY - ( myFontHeight / 4 ) ) ), myScaleBarMaxLabel ); } } //then the text itself theQPainter->setPen( myForeColor ); theQPainter->drawText( int( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ), int( myOriginY - ( myFontHeight / 4 ) ), myScaleBarMaxLabel ); // //Draw unit label // theQPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( myScaleBarUnitLabel ); myFontHeight = myFontMetrics.height(); //first the buffer for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { theQPainter->drawText( i + ( myOriginX + myScaleBarWidthInt + myTextOffsetX ), j + ( myOriginY + myMajorTickSize ), myScaleBarUnitLabel ); } } //then the text itself theQPainter->setPen( myForeColor ); theQPainter->drawText( ( myOriginX + myScaleBarWidthInt + myTextOffsetX ), ( myOriginY + myMajorTickSize ), myScaleBarUnitLabel ); } }
UnderlineModule::UnderlineModule() { ADD_INTERFACE_IMPL(UnderlineNoteAddin); enabled(false); }
bool streamEnabled() const {return enabled() && streamEnabledPure();}
void button::draw_contents() { surface image = image_; const int image_w = image_->w; int offset = 0; switch(state_) { case ACTIVE: image = activeImage_; break; case PRESSED: image = pressedImage_; if (type_ == TYPE_PRESS) offset = 1; break; case PRESSED_ACTIVE: image = pressedActiveImage_; break; case TOUCHED_NORMAL: case TOUCHED_PRESSED: image = touchedImage_; break; default: break; } SDL_Rect const &loc = location(); SDL_Rect clipArea = loc; const int texty = loc.y + loc.h / 2 - textRect_.h / 2 + offset; int textx; if (type_ != TYPE_CHECK && type_ != TYPE_RADIO && type_ != TYPE_IMAGE) textx = loc.x + image->w / 2 - textRect_.w / 2 + offset; else { clipArea.w += image_w + checkbox_horizontal_padding; textx = loc.x + image_w + checkbox_horizontal_padding / 2; } SDL_Color button_color = font::BUTTON_COLOR; if (!enabled()) { if (state_ == PRESSED || state_ == PRESSED_ACTIVE) image = pressedDisabledImage_; else image = disabledImage_; button_color = font::GRAY_COLOR; } if (!overlayImage_.null()) { surface noverlay = make_neutral_surface( enabled() ? overlayImage_ : overlayDisabledImage_); if (!overlayPressedImage_.null()) { switch (state_) { case ACTIVE: if (!overlayActiveImage_.null()) noverlay = make_neutral_surface(overlayActiveImage_); break; case PRESSED: case PRESSED_ACTIVE: case TOUCHED_NORMAL: case TOUCHED_PRESSED: noverlay = make_neutral_surface( enabled() ? overlayPressedImage_ : overlayPressedDisabledImage_); break; default: break; } } surface nimage = make_neutral_surface(image); blit_surface(noverlay, NULL, nimage, NULL); image = nimage; } video().blit_surface(loc.x, loc.y, image); if (type_ != TYPE_IMAGE){ clipArea.x += offset; clipArea.y += offset; clipArea.w -= 2*offset; clipArea.h -= 2*offset; font::draw_text(&video(), clipArea, font_size, button_color, label_, textx, texty); } update_rect(loc); }
void FlipCommand::onExecute(Context* context) { ContextWriter writer(context); Document* document = writer.document(); Sprite* sprite = writer.sprite(); { Transaction transaction(writer.context(), m_flipMask ? (m_flipType == doc::algorithm::FlipHorizontal ? "Flip Horizontal": "Flip Vertical"): (m_flipType == doc::algorithm::FlipHorizontal ? "Flip Canvas Horizontal": "Flip Canvas Vertical")); DocumentApi api = document->getApi(transaction); CelList cels; if (m_flipMask) { auto range = App::instance()->timeline()->range(); if (range.enabled()) cels = get_unique_cels(sprite, range); else if (writer.cel()) cels.push_back(writer.cel()); } else { for (Cel* cel : sprite->uniqueCels()) cels.push_back(cel); } Mask* mask = document->mask(); if (m_flipMask && document->isMaskVisible()) { Site site = *writer.site(); for (Cel* cel : cels) { site.frame(cel->frame()); site.layer(cel->layer()); int x, y; Image* image = site.image(&x, &y); if (!image) continue; // When the mask is inside the cel, we can try to flip the // pixels inside the image. if (cel->bounds().contains(mask->bounds())) { gfx::Rect flipBounds = mask->bounds(); flipBounds.offset(-x, -y); flipBounds &= image->bounds(); if (flipBounds.isEmpty()) continue; if (mask->bitmap() && !mask->isRectangular()) transaction.execute(new cmd::FlipMaskedCel(cel, m_flipType)); else api.flipImage(image, flipBounds, m_flipType); transaction.execute(new cmd::TrimCel(cel)); } // When the mask is bigger than the cel bounds, we have to // expand the cel, make the flip, and shrink it again. else { gfx::Rect flipBounds = (sprite->bounds() & mask->bounds()); if (flipBounds.isEmpty()) continue; ExpandCelCanvas expand( site, cel->layer(), TiledMode::NONE, transaction, ExpandCelCanvas::None); expand.validateDestCanvas(gfx::Region(flipBounds)); if (mask->bitmap() && !mask->isRectangular()) doc::algorithm::flip_image_with_mask( expand.getDestCanvas(), mask, m_flipType, document->bgColor(cel->layer())); else doc::algorithm::flip_image( expand.getDestCanvas(), flipBounds, m_flipType); expand.commit(); } } } else { for (Cel* cel : cels) { Image* image = cel->image(); api.setCelPosition (sprite, cel, (m_flipType == doc::algorithm::FlipHorizontal ? sprite->width() - image->width() - cel->x(): cel->x()), (m_flipType == doc::algorithm::FlipVertical ? sprite->height() - image->height() - cel->y(): cel->y())); api.flipImage(image, image->bounds(), m_flipType); } } // Flip the mask. Image* maskBitmap = mask->bitmap(); if (maskBitmap) { transaction.execute(new cmd::FlipMask(document, m_flipType)); // Flip the mask position because the if (!m_flipMask) transaction.execute( new cmd::SetMaskPosition( document, gfx::Point( (m_flipType == doc::algorithm::FlipHorizontal ? sprite->width() - mask->bounds().x2(): mask->bounds().x), (m_flipType == doc::algorithm::FlipVertical ? sprite->height() - mask->bounds().y2(): mask->bounds().y)))); document->generateMaskBoundaries(); } transaction.commit(); } update_screen_for_document(document); }
// Construct with specific option values. linger(bool e, int t) { enabled(e); timeout(t); }