Code highlightning testing thread No New Posts Tavern

Started by
moyack

0 Members and 1 Guest are viewing this topic.

Code highlightning testing thread
on: December 28, 2011, 09:41:18 PM

Code: C++
  1. Chapter03\colorandfont\main.cpp
  2.  /*
  3.   * Copyright (c) 2006-2007, Johan Thelin
  4.   *
  5.   * All rights reserved.
  6.   *
  7.   * Redistribution and use in source and binary forms, with or without modification,
  8.   * are permitted provided that the following conditions are met:
  9.   *
  10.   *     * Redistributions of source code must retain the above copyright notice,
  11.   *       this list of conditions and the following disclaimer.
  12.   *     * Redistributions in binary form must reproduce the above copyright notice, 
  13.   *       this list of conditions and the following disclaimer in the documentation
  14.   *       and/or other materials provided with the distribution.
  15.   *     * Neither the name of APress nor the names of its contributors
  16.   *       may be used to endorse or promote products derived from this software
  17.   *       without specific prior written permission.
  18.   *
  19.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20.   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21.   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22.   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23.   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24.   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25.   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26.   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27.   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28.   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29.   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.   *
  31.   */
  32.  
  33.  #include <QApplication>
  34.  
  35.  #include <QFontDialog>
  36.  #include <QColorDialog>
  37.  
  38.  class Tester : public QWidget
  39.  {
  40.  public:
  41.    void doColor()
  42.    {
  43.      QColor color = QColorDialog::getColor(Qt::yellow, this );
  44.      if( color.isValid() )
  45.      {
  46.  
  47.        qDebug( "ok" );
  48.      }
  49.    }
  50.    
  51.    void doFont()
  52.    {
  53.      bool ok;
  54.      QFont font = QFontDialog::getFont(
  55.                      &ok,
  56.                      QFont( "Arial", 18 ),
  57.                      this,
  58.                      tr("Pick a font") );
  59.      if( ok )
  60.      {
  61.        qDebug( "ok" );
  62.      }
  63.    }
  64.  };
  65.  
  66.  int main( int argc, char **argv )
  67.  {
  68.    QApplication app( argc, argv );
  69.    
  70.    Tester t;
  71.    t.doColor();
  72.    t.doFont();
  73.    
  74.    return 0;
  75.  }




Re: Code highlightning testing thread
Reply #1 on: December 29, 2011, 05:27:48 PM

Code: jass
  1. library TimedLoop
  2. //********************************************************
  3. //* TimedLoop
  4. //* ---------
  5. //*
  6. //* Requires jasshelper 0.9.G.1 or greater.
  7. //*
  8. //*   A library + module that are meant to make those
  9. //* array + timer loops easy, yet still faster than
  10. //* other alternatives meant to be easy (In other words
  11. //* no TriggerEvaluate is involved).
  12. //*
  13. //* The OOPness is interesting.
  14. //*
  15. //*  Before implementing TimedLoop
  16. //* your struct needs an onTimedLoop method that takes
  17. //* nothing and returns boolean, if the method
  18. //* returns false, the instance will get removed
  19. //* from the loop and destroyed, else it will continue,
  20. //* think of it as if the call asks the method a
  21. //* question: "Should I continue the loop afterwards?"
  22. //*
  23. //* Alternatively, if you are not convinced, you may
  24. //* use the TimedLoop_CONTINUE and TimedLoop_STOP
  25. //* constants in the method's returns.
  26. //*
  27. //*   After implementing TimedLoop, you can call
  28. //* the startTimedLoop method to add the periodic event
  29. //* to that instance, only call it once per instance.
  30. //*
  31. //* I recommend to call implement just bellow the
  32. //* declaration of the onLoop method, else it will
  33. //* actually use TriggerEvaluate, which is lame. Remind
  34. //* me to implement a topsort in jasshelper.
  35. //*
  36. //*  If you feel the need to destroy the struct outside
  37. //* the loop, well, you'll have to add a flag to it so
  38. //* you send a message to onLoop to make it return false.
  39. //* A more complicated module to allow that easily would
  40. //* come later.
  41. //*
  42. //********************************************************
  43.  
  44. //========================================================
  45. // config:
  46.  
  47.     globals
  48.      public constant real    PERIOD = 0.025
  49.      // A lower value and everything using the module will
  50.      // look better, yet performance will drop.
  51.     endglobals
  52.  
  53. //========================================================
  54. // implementation:
  55. //
  56.    globals
  57.     public constant boolean STOP     = false
  58.     public constant boolean CONTINUE = true
  59.    endglobals
  60.    
  61.    
  62.    //=========================== 
  63.    module TimedLoop
  64.    // god bless private module members.
  65.    //
  66.       private static thistype array V        // The array
  67.       private static integer        N = 0    // The count
  68.       private static timer          T = null // the timer, one per
  69.                                              // struct that implements this
  70.      
  71.       private static method onExpire takes nothing returns nothing
  72.        local integer  n    = 0
  73.        local thistype this // yay for odd-sounding syntax constructs
  74.        local integer  i    = 0
  75.        
  76.           loop
  77.               exitwhen (i== thistype.N)
  78.               set this = .V[i]
  79.               if ( this.onTimedLoop() == CONTINUE ) then
  80.                   set .V[n] = this
  81.                   set n=n+1
  82.               else
  83.                   call this.destroy()
  84.               endif
  85.               set i=i+1
  86.           endloop
  87.           set thistype.N = n
  88.           if (n== 0) then
  89.               call PauseTimer(.T)
  90.           endif
  91.                  
  92.       endmethod
  93.      
  94.       public method startTimedLoop takes nothing returns nothing
  95.          set .V[.N] = this
  96.          set .N=.N + 1
  97.          if (.N == 1) then
  98.              if (.T == null) then
  99.                  set .T = CreateTimer()
  100.              endif
  101.              call TimerStart(.T, PERIOD, true, function thistype.onExpire)
  102.          endif
  103.       endmethod
  104.      
  105.    endmodule
  106.  
  107.  
  108. endlibrary
  109.  
« Last Edit: December 29, 2011, 05:38:38 PM by moyack »



 

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...