├── c ├── README.txt ├── CMakeLists.txt └── main.c ├── cpp ├── README.txt ├── square.h ├── square.cpp ├── CMakeLists.txt └── main.cpp ├── qt4-gui ├── README.txt ├── src │ ├── CMakeLists.txt │ └── LoadImage │ │ ├── LoadImage.h │ │ ├── CMakeLists.txt │ │ ├── LoadImage.cpp │ │ └── LoadImage.ui ├── demo │ ├── CMakeLists.txt │ └── DemoLoadImage │ │ ├── CMakeLists.txt │ │ └── main.cpp ├── images │ └── demo.jpg ├── Configs.h.in └── CMakeLists.txt ├── modules ├── includes │ ├── cubic.h │ ├── square.h │ └── extras.h ├── src │ ├── square │ │ ├── CMakeLists.txt │ │ └── square.c │ ├── cubic │ │ ├── CMakeLists.txt │ │ └── cubic.c │ ├── CMakeLists.txt │ └── extras │ │ ├── power4.c │ │ ├── CMakeLists.txt │ │ └── power5.c ├── CMakeLists.txt ├── demo │ ├── CMakeLists.txt │ └── calc.c └── README.txt ├── qt4-console ├── README.txt ├── main.cpp └── CMakeLists.txt ├── boost ├── README.txt ├── main.cpp └── CMakeLists.txt ├── opencv3 ├── README.txt ├── CMakeLists.txt └── example.cpp ├── qt4-project ├── images │ ├── brick.png │ └── qt-logo.png ├── basicdrawing.qrc ├── README.txt ├── CMakeLists.txt ├── main.cpp ├── renderarea.h ├── window.h ├── renderarea.cpp └── window.cpp ├── .gitignore ├── cpp11_vs2010 ├── CMakeLists.txt └── main.cpp ├── qt5-project ├── main.cpp └── CMakeLists.txt ├── opencv ├── CMakeLists.txt ├── README.txt └── minarea.c ├── cpp11 ├── main.cpp ├── CMakeLists.txt └── README.txt ├── LICENSE └── README.md /c/README.txt: -------------------------------------------------------------------------------- 1 | simple c. 2 | -------------------------------------------------------------------------------- /cpp/README.txt: -------------------------------------------------------------------------------- 1 | simple cpp. 2 | -------------------------------------------------------------------------------- /cpp/square.h: -------------------------------------------------------------------------------- 1 | double square( double x ); 2 | -------------------------------------------------------------------------------- /qt4-gui/README.txt: -------------------------------------------------------------------------------- 1 | advanced qt gui application. 2 | -------------------------------------------------------------------------------- /modules/includes/cubic.h: -------------------------------------------------------------------------------- 1 | double cubic( double x ); 2 | -------------------------------------------------------------------------------- /modules/includes/square.h: -------------------------------------------------------------------------------- 1 | double square( double x ); 2 | -------------------------------------------------------------------------------- /qt4-console/README.txt: -------------------------------------------------------------------------------- 1 | simple qt console application. 2 | -------------------------------------------------------------------------------- /boost/README.txt: -------------------------------------------------------------------------------- 1 | simple cpp with BOOST library support. 2 | -------------------------------------------------------------------------------- /qt4-gui/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory( LoadImage ) 2 | -------------------------------------------------------------------------------- /qt4-gui/demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory( DemoLoadImage ) 2 | -------------------------------------------------------------------------------- /modules/src/square/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( LibSquare square.c ) 2 | -------------------------------------------------------------------------------- /modules/src/cubic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( LibCubic ${CUBICS} cubic.c ) 2 | -------------------------------------------------------------------------------- /modules/includes/extras.h: -------------------------------------------------------------------------------- 1 | double power4( double x ); 2 | double power5( double x ); 3 | -------------------------------------------------------------------------------- /cpp/square.cpp: -------------------------------------------------------------------------------- 1 | #include "square.h" 2 | 3 | double square( double x ) 4 | { 5 | return x*x; 6 | } 7 | -------------------------------------------------------------------------------- /opencv3/README.txt: -------------------------------------------------------------------------------- 1 | See more at: https://github.com/Itseez/opencv/tree/master/samples/cpp/example_cmake 2 | -------------------------------------------------------------------------------- /qt4-gui/images/demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/cmake-templates/master/qt4-gui/images/demo.jpg -------------------------------------------------------------------------------- /modules/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory( cubic ) 2 | add_subdirectory( extras ) 3 | add_subdirectory( square ) 4 | -------------------------------------------------------------------------------- /qt4-project/images/brick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/cmake-templates/master/qt4-project/images/brick.png -------------------------------------------------------------------------------- /c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( C ) 2 | cmake_minimum_required( VERSION 2.6 ) 3 | add_executable( ${PROJECT_NAME} main.c ) 4 | -------------------------------------------------------------------------------- /modules/src/cubic/cubic.c: -------------------------------------------------------------------------------- 1 | #include "cubic.h" 2 | 3 | double cubic( double x ) 4 | { 5 | return x * x * x; 6 | } 7 | -------------------------------------------------------------------------------- /modules/src/square/square.c: -------------------------------------------------------------------------------- 1 | #include "square.h" 2 | 3 | double square( double x ) 4 | { 5 | return x * x; 6 | } 7 | -------------------------------------------------------------------------------- /qt4-project/images/qt-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/cmake-templates/master/qt4-project/images/qt-logo.png -------------------------------------------------------------------------------- /modules/src/extras/power4.c: -------------------------------------------------------------------------------- 1 | #include "extras.h" 2 | 3 | double power4( double x ) 4 | { 5 | return x * x * x * x; 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | CMakeScripts 4 | Makefile 5 | cmake_install.cmake 6 | install_manifest.txt 7 | build/ 8 | -------------------------------------------------------------------------------- /cpp11_vs2010/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( CPP11_VS2010 ) 2 | cmake_minimum_required( VERSION 2.8 ) 3 | add_executable( ${PROJECT_NAME} main.cpp ) 4 | -------------------------------------------------------------------------------- /modules/src/extras/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file (GLOB EXTRAS *.c) 2 | add_library( LibExtras ${EXTRAS} ) 3 | target_link_libraries( LibExtras LibSquare LibCubic ) 4 | -------------------------------------------------------------------------------- /cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( CPP ) 2 | cmake_minimum_required( VERSION 2.6 ) 3 | file( GLOB SRCS *.c *.cpp *.cc *.h *.hpp ) 4 | add_executable( ${PROJECT_NAME} ${SRCS} ) 5 | -------------------------------------------------------------------------------- /qt4-gui/Configs.h.in: -------------------------------------------------------------------------------- 1 | // 请修改 工程根目录的 Configs.h.in 而不是直接修改这个文件。 2 | 3 | #define CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@" 4 | #define IMAGE_DIR "@CMAKE_SOURCE_DIR@/images" 5 | -------------------------------------------------------------------------------- /c/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main ( int argc, char **argv ) 4 | { 5 | fprintf( stdout, "%s", "Hello World.\n" ); 6 | getchar(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /modules/src/extras/power5.c: -------------------------------------------------------------------------------- 1 | #include "extras.h" 2 | #include "square.h" 3 | #include "cubic.h" 4 | 5 | double power5( double x ) 6 | { 7 | return cubic(x) * square(x); 8 | } 9 | -------------------------------------------------------------------------------- /qt4-gui/demo/DemoLoadImage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( DemoLoadImage ) 2 | add_executable( ${PROJECT_NAME} main.cpp ) 3 | target_link_libraries( ${PROJECT_NAME} ${QT_LIBRARIES} LoadImage ) 4 | -------------------------------------------------------------------------------- /qt4-project/basicdrawing.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/brick.png 4 | images/qt-logo.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /qt5-project/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main( int argc, char **argv ) 4 | { 5 | QApplication app( argc, argv ); 6 | qDebug() << QString( "Hello World." ); 7 | app.exec(); 8 | } 9 | -------------------------------------------------------------------------------- /modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( MODULES ) 2 | cmake_minimum_required( VERSION 2.8.3 ) 3 | 4 | include_directories( ${CMAKE_SOURCE_DIR}/includes ) 5 | 6 | add_subdirectory( src ) 7 | add_subdirectory( demo ) 8 | -------------------------------------------------------------------------------- /opencv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( OPENCV ) 2 | cmake_minimum_required( VERSION 2.6 ) 3 | 4 | find_package( OpenCV REQUIRED ) 5 | add_executable( ${PROJECT_NAME} minarea.c ) 6 | target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} ) 7 | -------------------------------------------------------------------------------- /opencv/README.txt: -------------------------------------------------------------------------------- 1 | Mods of OpenCV official example cmake demo: 2 | 3 | 4 | 5 | See cpp version at: 6 | 7 | + 8 | -------------------------------------------------------------------------------- /qt4-console/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main( int argc, char **argv ) 5 | { 6 | QCoreApplication app( argc, argv ); 7 | qDebug() << QString( "Hello World." ); 8 | app.exec(); 9 | } 10 | -------------------------------------------------------------------------------- /qt4-gui/demo/DemoLoadImage/main.cpp: -------------------------------------------------------------------------------- 1 | #include "LoadImage.h" 2 | #include 3 | 4 | int main( int argc, char **argv ) 5 | { 6 | QApplication a( argc, argv ); 7 | LoadImage li; 8 | li.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /qt4-console/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( QT4_CONSOLE ) 2 | cmake_minimum_required( VERSION 2.6 ) 3 | 4 | find_package( Qt4 REQUIRED ) 5 | include( ${QT_USE_FILE} ) 6 | set( QT_DONT_USE_QTGUI TRUE ) 7 | 8 | add_executable( ${PROJECT_NAME} main.cpp ) 9 | target_link_libraries( ${PROJECT_NAME} ${QT_LIBRARIES} ) 10 | -------------------------------------------------------------------------------- /modules/demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( CALC ) 2 | cmake_minimum_required( VERSION 2.6 ) 3 | 4 | set( EXTRA_LIBS ${EXTRA_LIBS} LibSquare ) 5 | set( EXTRA_LIBS ${EXTRA_LIBS} LibExtras ) 6 | set( EXTRA_LIBS ${EXTRA_LIBS} LibCubic ) 7 | 8 | add_executable( Calc calc.c ) 9 | target_link_libraries( Calc ${EXTRA_LIBS} ) 10 | -------------------------------------------------------------------------------- /modules/README.txt: -------------------------------------------------------------------------------- 1 | This demo shows how to organize code with CMake. 2 | 3 | exe <--- calc.c 4 | calc.c <---depends on---+ includes/*.h (declarations) 5 | \_ static libs (implementations) 6 | \_ LibSquare: src/square.c 7 | |_ LibCubic: src/cubic.c 8 | |_ LibExtras: src/{power4.c, power5.c} 9 | -------------------------------------------------------------------------------- /qt4-gui/src/LoadImage/LoadImage.h: -------------------------------------------------------------------------------- 1 | #ifndef LOADIMAGE_H 2 | #define LOADIMAGE_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class LoadImage; 8 | } 9 | 10 | class LoadImage : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit LoadImage(QWidget *parent = 0); 16 | ~LoadImage(); 17 | 18 | private slots: 19 | void on_pushButton_loadimg_clicked(); 20 | 21 | private: 22 | Ui::LoadImage *ui; 23 | }; 24 | 25 | #endif // LOADIMAGE_H 26 | -------------------------------------------------------------------------------- /cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "square.h" 6 | 7 | int main ( int argc, char **argv ) 8 | { 9 | std::vector v(3, 0); 10 | v[2] = 2; 11 | v.push_back(3); 12 | v.push_back(4); 13 | 14 | for( std::vector::iterator it = v.begin(); it != v.end(); ++it ) { 15 | std::cout << *it << "^2\t--->\t" << square(*it) << std::endl; 16 | } 17 | 18 | getchar(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /boost/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main( int argc, char **argv ) 6 | { 7 | boost::timer t; 8 | std::cout << "max timespan: " 9 | << t.elapsed_max() / 3600 << "h" << std::endl; 10 | std::cout << "min timespan: " 11 | << t.elapsed_min() << "s" << std::endl; 12 | std::cout << "now times elapsed: " 13 | << t.elapsed() << "s" << std::endl; 14 | 15 | getchar(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /modules/demo/calc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "square.h" 3 | #include "cubic.h" 4 | #include "extras.h" 5 | 6 | int main ( int argc, char **argv ) 7 | { 8 | double x = 9.8; 9 | fprintf( stdout, "Square of %5.2f is %18.6f\n", x, square(x) ); 10 | fprintf( stdout, "Cubic of %5.2f is %18.6f\n", x, cubic(x) ); 11 | fprintf( stdout, "x^4 of %5.2f is %18.6f\n", x, power4(x) ); 12 | fprintf( stdout, "x^5 of %5.2f is %18.6f\n", x, power5(x) ); 13 | 14 | getchar(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /opencv3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( OPENCV3 ) 2 | cmake_minimum_required( VERSION 2.8 ) 3 | 4 | find_package( OpenCV REQUIRED ) 5 | 6 | message( STATUS "OpenCV library status:" ) 7 | message( STATUS " version: ${OpenCV_VERSION}" ) 8 | message( STATUS " libraries: ${OpenCV_LIBS}" ) 9 | message( STATUS " include path: ${OpenCV_INCLUDE_DIRS}" ) 10 | 11 | include_directories( ${OpenCV_INCLUDE_DIRS} ) 12 | 13 | add_executable( ${PROJECT_NAME} example.cpp ) 14 | target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} ) 15 | -------------------------------------------------------------------------------- /boost/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( BOOST ) 2 | cmake_minimum_required( VERSION 2.6 ) 3 | 4 | find_package( Boost REQUIRED ) 5 | INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) 6 | LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS} ) 7 | set( Boost_USE_STATIC_LIBS OFF ) 8 | set( Boost_USE_MULTITHREADED ON ) 9 | set( Boost_USE_STATIC_RUNTIME OFF ) 10 | set( BOOST_ALL_DYN_LINK ON ) # force dynamic linking for all libraries 11 | 12 | add_executable( ${PROJECT_NAME} main.cpp ) 13 | target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES} ) 14 | -------------------------------------------------------------------------------- /cpp11_vs2010/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main( void ) 7 | { 8 | std::vector v(3, 0); 9 | v[0] = 3; 10 | v[2] = 1; 11 | v.push_back( 25 ); 12 | v.push_back( 13 ); 13 | 14 | std::sort( v.begin(), v.end(), [](int x, int y){ return x 2 | #include 3 | #include 4 | #include 5 | 6 | int main( void ) 7 | { 8 | std::vector v = {7, 5, 16, 8}; 9 | 10 | v.push_back( 25 ); 11 | v.push_back( 13 ); 12 | 13 | auto it = v.cbegin(); 14 | while ( it != v.cend() ) { 15 | std::cout << '\t' << *it; 16 | ++it; 17 | } 18 | std::cout << "\n"; 19 | 20 | std::sort( v.begin(), v.end(), [](int x, int y){ return x 4 | #include 5 | #include 6 | #include "Configs.h" 7 | 8 | #ifndef IMAGE_DIR 9 | #define IMAGE_DIR "" 10 | #endif 11 | 12 | LoadImage::LoadImage(QWidget *parent) : 13 | QWidget(parent), 14 | ui(new Ui::LoadImage) 15 | { 16 | ui->setupUi(this); 17 | } 18 | 19 | LoadImage::~LoadImage() 20 | { 21 | delete ui; 22 | } 23 | 24 | void LoadImage::on_pushButton_loadimg_clicked() 25 | { 26 | QString fileName = QFileDialog::getOpenFileName( 0, QString(), IMAGE_DIR, 27 | tr("Images (*.png *.jpg)") ); 28 | QImage image; 29 | if ( !image.load(fileName) ) { 30 | ui->image_label->setText( tr("Selected file is not an image, please select another.") ); 31 | return; 32 | } 33 | ui->image_label->setPixmap( QPixmap::fromImage(image) ); 34 | } 35 | -------------------------------------------------------------------------------- /cpp11/README.txt: -------------------------------------------------------------------------------- 1 | Tested C++ feauture: 2 | 3 | - auto 4 | - const iterator 5 | - lambda calculas 6 | - new for loop (foreach) 7 | 8 | In Visual Studio 2010, you can use: 9 | 10 | - auto 11 | - const iterator 12 | - lambda calculas 13 | 14 | without any setup, see CMakeLists.txt for further infomation. 15 | 16 | ------------------------------------------------------------- 17 | 18 | C++11 support can't be covered in a simple and elegant CMakeLists.txt, 19 | you I won't continue test C++11 features here further. These links may 20 | be useful: 21 | 22 | - 23 | - 24 | 25 | My advice is: 26 | 27 | - don't use `for( int i, v )' feature 28 | - be conservative, use lambda, const iterator, auto is pretty much enough 29 | - for VS2010 project, check 30 | 31 | - for Linux GNUMake, this CMakeList.txt works fine 32 | -------------------------------------------------------------------------------- /qt4-gui/src/LoadImage/LoadImage.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoadImage 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | LoadImage 15 | 16 | 17 | 18 | 19 | 20 | Load An Image 21 | 22 | 23 | 24 | 25 | 26 | 27 | No Image Loaded. 28 | 29 | 30 | Qt::AlignCenter 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 TANG ZhiXiong (dvorak4tzx) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /opencv3/example.cpp: -------------------------------------------------------------------------------- 1 | #include "opencv2/core.hpp" 2 | #include "opencv2/imgproc.hpp" 3 | #include "opencv2/highgui.hpp" 4 | #include "opencv2/videoio.hpp" 5 | #include 6 | 7 | using namespace cv; 8 | using namespace std; 9 | 10 | void drawText(Mat & image); 11 | 12 | int main() 13 | { 14 | cout << "Built with OpenCV " << CV_VERSION << endl; 15 | Mat image; 16 | VideoCapture capture; 17 | capture.open(0); 18 | if(capture.isOpened()) 19 | { 20 | cout << "Capture is opened" << endl; 21 | for(;;) 22 | { 23 | capture >> image; 24 | if(image.empty()) 25 | break; 26 | drawText(image); 27 | imshow("Sample", image); 28 | if(waitKey(10) >= 0) 29 | break; 30 | } 31 | } 32 | else 33 | { 34 | cout << "No capture" << endl; 35 | image = Mat::zeros(480, 640, CV_8UC1); 36 | drawText(image); 37 | imshow("Sample", image); 38 | waitKey(0); 39 | } 40 | return 0; 41 | } 42 | 43 | void drawText(Mat & image) 44 | { 45 | putText(image, "Hello OpenCV", 46 | Point(20, 50), 47 | FONT_HERSHEY_COMPLEX, 1, // font face and scale 48 | Scalar(255, 255, 255), // white 49 | 1, LINE_AA); // line thickness and type 50 | } 51 | -------------------------------------------------------------------------------- /qt4-project/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( QT4 ) 2 | cmake_minimum_required( VERSION 2.6 ) 3 | 4 | find_package( Qt4 REQUIRED ) 5 | include( ${QT_USE_FILE} ) 6 | 7 | include_directories( ${CMAKE_SOURCE_DIR}/) 8 | include_directories( ${CMAKE_BINARY_DIR}/) 9 | 10 | # based on: https://cmake.org/Wiki/CMakeMacroFilterOut 11 | macro( filter_out FILTERS INPUTS OUTPUTS ) 12 | set( FOUT "" ) 13 | foreach( INP ${INPUTS} ) 14 | set( FILTERED 0 ) 15 | foreach( FILT ${FILTERS} ) 16 | if( ${FILTERED} EQUAL 0 ) 17 | if( "${FILT}" STREQUAL "${INP}" ) 18 | set( FILTERED 1 ) 19 | endif( "${FILT}" STREQUAL "${INP}" ) 20 | if( ${INP} MATCHES ${FILT} ) 21 | set( FILTERED 1 ) 22 | endif( ${INP} MATCHES ${FILT} ) 23 | endif( ${FILTERED} EQUAL 0 ) 24 | endforeach( FILT ${FILTERS} ) 25 | if( ${FILTERED} EQUAL 0 ) 26 | set( FOUT ${FOUT} ${INP} ) 27 | endif( ${FILTERED} EQUAL 0 ) 28 | endforeach( INP ${INPUTS} ) 29 | set( ${OUTPUTS} ${FOUT} ) 30 | endmacro( filter_out FILTERS INPUTS OUTPUTS ) 31 | 32 | file( GLOB_RECURSE UI_FILES *.ui ) 33 | file( GLOB_RECURSE HDRS_FILES *.h *.hpp ) 34 | file( GLOB_RECURSE SRCS_FILES *.cpp *.c) 35 | file( GLOB_RECURSE RCS_FILES *.qrc ) 36 | 37 | set( FILTERS ".*CompilerId.*" ) 38 | filter_out("${FILTERS}" "${SRCS_FILES}" SRCS_FILES ) 39 | 40 | qt4_wrap_cpp( MOC_SRCS ${HDRS_FILES} ) 41 | qt4_wrap_ui( UI_HDRS ${UI_FILES} ) 42 | qt4_add_resources( RCS ${RCS_FILES} ) 43 | 44 | source_group( "UI Files" FILES ${UI_FILES} ) 45 | source_group( "Generated Files" FILES ${MOC_SRCS} ${UI_HDRS} ) 46 | source_group( "All Resource Files" FILES ${RCS} ) 47 | 48 | add_executable( ${PROJECT_NAME} 49 | ${MOC_SRCS} 50 | ${HDRS_FILES} 51 | ${SRCS_FILES} 52 | ${UI_FILES} 53 | ${UI_HDRS} ${RCS} ) 54 | target_link_libraries( ${PROJECT_NAME} ${QT_LIBRARIES} ) 55 | -------------------------------------------------------------------------------- /qt4-project/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #include 42 | 43 | #include "window.h" 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | Q_INIT_RESOURCE(basicdrawing); 48 | 49 | QApplication app(argc, argv); 50 | Window window; 51 | #if defined(Q_OS_SYMBIAN) 52 | window.showMaximized(); 53 | #else 54 | window.show(); 55 | #endif 56 | return app.exec(); 57 | } 58 | -------------------------------------------------------------------------------- /qt4-project/renderarea.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #ifndef RENDERAREA_H 42 | #define RENDERAREA_H 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | //! [0] 50 | class RenderArea : public QWidget 51 | { 52 | Q_OBJECT 53 | 54 | public: 55 | enum Shape { Line, Points, Polyline, Polygon, Rect, RoundedRect, Ellipse, Arc, 56 | Chord, Pie, Path, Text, Pixmap }; 57 | 58 | RenderArea(QWidget *parent = 0); 59 | 60 | QSize minimumSizeHint() const; 61 | QSize sizeHint() const; 62 | 63 | public slots: 64 | void setShape(Shape shape); 65 | void setPen(const QPen &pen); 66 | void setBrush(const QBrush &brush); 67 | void setAntialiased(bool antialiased); 68 | void setTransformed(bool transformed); 69 | 70 | protected: 71 | void paintEvent(QPaintEvent *event); 72 | 73 | private: 74 | Shape shape; 75 | QPen pen; 76 | QBrush brush; 77 | bool antialiased; 78 | bool transformed; 79 | QPixmap pixmap; 80 | }; 81 | //! [0] 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /qt4-project/window.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #ifndef WINDOW_H 42 | #define WINDOW_H 43 | 44 | #include 45 | 46 | QT_BEGIN_NAMESPACE 47 | class QCheckBox; 48 | class QComboBox; 49 | class QLabel; 50 | class QSpinBox; 51 | QT_END_NAMESPACE 52 | class RenderArea; 53 | 54 | //! [0] 55 | class Window : public QWidget 56 | { 57 | Q_OBJECT 58 | 59 | public: 60 | Window(); 61 | 62 | private slots: 63 | void shapeChanged(); 64 | void penChanged(); 65 | void brushChanged(); 66 | 67 | private: 68 | RenderArea *renderArea; 69 | QLabel *shapeLabel; 70 | QLabel *penWidthLabel; 71 | QLabel *penStyleLabel; 72 | QLabel *penCapLabel; 73 | QLabel *penJoinLabel; 74 | QLabel *brushStyleLabel; 75 | QLabel *otherOptionsLabel; 76 | QComboBox *shapeComboBox; 77 | QSpinBox *penWidthSpinBox; 78 | QComboBox *penStyleComboBox; 79 | QComboBox *penCapComboBox; 80 | QComboBox *penJoinComboBox; 81 | QComboBox *brushStyleComboBox; 82 | QCheckBox *antialiasingCheckBox; 83 | QCheckBox *transformationsCheckBox; 84 | }; 85 | //! [0] 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /opencv/minarea.c: -------------------------------------------------------------------------------- 1 | #ifdef _CH_ 2 | #pragma package 3 | #endif 4 | 5 | #ifndef _EiC 6 | #include "cv.h" 7 | #include "highgui.h" 8 | #include 9 | #include 10 | #endif 11 | 12 | #define ARRAY 1 13 | 14 | void help() 15 | { 16 | printf("\nThis program demonstrates finding the minimum enclosing box or circle of a set\n" 17 | "of points using functions: minAreaRect() minEnclosingCircle().\n" 18 | "Random points are generated and then enclosed.\n" 19 | "Call:\n" 20 | "./minarea\n"); 21 | } 22 | 23 | int main( int argc, char** argv ) 24 | { 25 | IplImage* img = cvCreateImage( cvSize( 500, 500 ), 8, 3 ); 26 | #if !ARRAY 27 | CvMemStorage* storage = cvCreateMemStorage(0); 28 | #endif 29 | help(); 30 | cvNamedWindow( "rect & circle", 1 ); 31 | 32 | for(;;) 33 | { 34 | char key; 35 | int i, count = rand()%100 + 1; 36 | CvPoint pt0, pt; 37 | CvBox2D box; 38 | CvPoint2D32f box_vtx[4]; 39 | CvPoint2D32f center; 40 | CvPoint icenter; 41 | float radius; 42 | #if !ARRAY 43 | CvSeq* ptseq = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvContour), 44 | sizeof(CvPoint), storage ); 45 | for( i = 0; i < count; i++ ) 46 | { 47 | pt0.x = rand() % (img->width/2) + img->width/4; 48 | pt0.y = rand() % (img->height/2) + img->height/4; 49 | cvSeqPush( ptseq, &pt0 ); 50 | } 51 | #ifndef _EiC /* unfortunately, here EiC crashes */ 52 | box = cvMinAreaRect2( ptseq, 0 ); 53 | #endif 54 | cvMinEnclosingCircle( ptseq, ¢er, &radius ); 55 | #else 56 | CvPoint* points = (CvPoint*)malloc( count * sizeof(points[0])); 57 | CvMat pointMat = cvMat( 1, count, CV_32SC2, points ); 58 | 59 | for( i = 0; i < count; i++ ) 60 | { 61 | pt0.x = rand() % (img->width/2) + img->width/4; 62 | pt0.y = rand() % (img->height/2) + img->height/4; 63 | points[i] = pt0; 64 | } 65 | #ifndef _EiC 66 | box = cvMinAreaRect2( &pointMat, 0 ); 67 | #endif 68 | cvMinEnclosingCircle( &pointMat, ¢er, &radius ); 69 | #endif 70 | cvBoxPoints( box, box_vtx ); 71 | cvZero( img ); 72 | for( i = 0; i < count; i++ ) 73 | { 74 | #if !ARRAY 75 | pt0 = *CV_GET_SEQ_ELEM( CvPoint, ptseq, i ); 76 | #else 77 | pt0 = points[i]; 78 | #endif 79 | cvCircle( img, pt0, 2, CV_RGB( 255, 0, 0 ), CV_FILLED, CV_AA, 0 ); 80 | } 81 | 82 | #ifndef _EiC 83 | pt0.x = cvRound(box_vtx[3].x); 84 | pt0.y = cvRound(box_vtx[3].y); 85 | for( i = 0; i < 4; i++ ) 86 | { 87 | pt.x = cvRound(box_vtx[i].x); 88 | pt.y = cvRound(box_vtx[i].y); 89 | cvLine(img, pt0, pt, CV_RGB(0, 255, 0), 1, CV_AA, 0); 90 | pt0 = pt; 91 | } 92 | #endif 93 | icenter.x = cvRound(center.x); 94 | icenter.y = cvRound(center.y); 95 | cvCircle( img, icenter, cvRound(radius), CV_RGB(255, 255, 0), 1, CV_AA, 0 ); 96 | 97 | cvShowImage( "rect & circle", img ); 98 | 99 | key = (char) cvWaitKey(0); 100 | if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC' 101 | break; 102 | 103 | #if !ARRAY 104 | cvClearMemStorage( storage ); 105 | #else 106 | free( points ); 107 | #endif 108 | } 109 | 110 | cvDestroyWindow( "rect & circle" ); 111 | return 0; 112 | } 113 | 114 | #ifdef _EiC 115 | main(1,"convexhull.c"); 116 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cmake-templates 2 | 3 | Some CMake Templates. 4 | 5 | ## Conventions 6 | 7 | - VS2010 means Windows Visual Studio 2010 project 8 | - Linux means GNU Makefile project 9 | - :smile: means tested okay 10 | - :cry: means test result not sufficiently good 11 | - :question: means not tested yet 12 | - so VS2010 :smile: means the CMakeLists.txt tests good on Visual Studio 2010 13 | 14 | ## Usage 15 | 16 | ### Windows 17 | 18 | Use `CMake-GUI` to generate Viisual Studio 2010 project, then use Visual Studio to compile & run. 19 | 20 | Tutorial: [HOWTO: CMake + Visual Studio 2010 · Issue #1 · district10/cmake-templates](https://github.com/district10/cmake-templates/issues/1). 21 | 22 | ### Linux 23 | 24 | ```bash 25 | # cd source dir (there should be a CMakeLists.txt) 26 | mkdir build && cd build 27 | cmake .. 28 | make 29 | 30 | # then checkout the generated binary files 31 | ``` 32 | 33 | ## C Example 34 | 35 | Simple C project. See [c](c). (VS2010 :smile:, Linux :smile:) 36 | 37 | ## C++ Example 38 | 39 | Simple C++ project. See [cpp](cpp). (VS2010 :smile:, Linux :smile:) 40 | 41 | ## C++11 Example 42 | 43 | C++ project. See [cpp11](cpp11). (VS2010 :cry: :question:, Linux :smile:) 44 | 45 | C++11 (aka C++0x) features works on Linux: 46 | 47 | - auto 48 | - const iterator 49 | - foreach (I mean `for(type varname, container)`.) 50 | - lambda function 51 | 52 | On VS2010: 53 | 54 | - auto 55 | - const iterator 56 | - lambda function 57 | 58 | VS2010 by default supports 1) auto; 2) const iterator; 3) lambda, but not foreach. 59 | See [cpp11/CMakeLists.txt](cpp11/CMakeLists.txt) for further infomation. 60 | 61 | Bonus: A VS2010 example with some C++11 features: [cpp11_vs2010](cpp11_vs2010). 62 | 63 | ## Example to Show How to Modualize Your Project 64 | 65 | See [modules](modules). (VS2010 :smile:, Linux :smile:) 66 | 67 | ## Example with Support of Boost 68 | 69 | See [boost](boost). (VS2010 :smile:, Linux :smile:) 70 | 71 | ## Example with Support of OpenCV 72 | 73 | See 74 | 75 | - [opencv](opencv): for opencv2 or less (VS2010 :smile:, Linux :question:) 76 | - [opencv3](opencv3): for opencv3 (temporarily not available) (VS2010 :question:, Linux :smile:) 77 | 78 | (I have OpenCV2 on Win, and OpenCV3 on Linux, that's why...) 79 | 80 | ## Example with Support of Qt4 81 | 82 | See 83 | 84 | - [qt4 console application](qt4-console) (VS2010 :smile:, Linux :smile:) 85 | - [qt4 GUI application](qt4-gui) (check out the [configs.h.in](qt4-gui/configs.h.in) file) (VS2010 :smile:, Linux :smile:) 86 | - [qt4 application for lazy people](qt4-project), works like `qmake -project && qmake && make` on Linux (VS2010 :smile:, Linux :smile:) 87 | 88 | ## Example with Support of Qt5 89 | 90 | TODO 91 | 92 | ## TODO 93 | 94 | - More documentation 95 | - More elegant & illustrative examples 96 | - Planned Examples 97 | + for Windows, link `*.lib` files 98 | + for Linux, link `*.a`, `*.so` files, set `rpath` 99 | + *etc.* 100 | 101 | ## ReadingList 102 | 103 | These links may be useful: 104 | 105 | - [Search · cmake templates](https://github.com/search?utf8=%E2%9C%93&q=cmake+templates) 106 | - [giddie/qt-cmake-template: Project template using CMake / Qt / NSIS or WiX / MinGW or MSVS combined in easy-to-use form](https://github.com/giddie/qt-cmake-template) 107 | - [cginternals/cmake-init: Template for reliable, cross-platform C++ project setup using cmake.](https://github.com/cginternals/cmake-init) 108 | - [district10/algo: 重复造轮子。](https://github.com/district10/algo) 109 | 110 | ## Koan 111 | 112 | - CMake's documentation is not for human. It really smells 113 | - Adapt to different standards is by no means easy 114 | -------------------------------------------------------------------------------- /qt4-project/renderarea.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #include 42 | 43 | #include "renderarea.h" 44 | 45 | //! [0] 46 | RenderArea::RenderArea(QWidget *parent) 47 | : QWidget(parent) 48 | { 49 | shape = Polygon; 50 | antialiased = false; 51 | transformed = false; 52 | pixmap.load(":/images/qt-logo.png"); 53 | 54 | setBackgroundRole(QPalette::Base); 55 | setAutoFillBackground(true); 56 | } 57 | //! [0] 58 | 59 | //! [1] 60 | QSize RenderArea::minimumSizeHint() const 61 | { 62 | return QSize(100, 100); 63 | } 64 | //! [1] 65 | 66 | //! [2] 67 | QSize RenderArea::sizeHint() const 68 | { 69 | return QSize(400, 200); 70 | } 71 | //! [2] 72 | 73 | //! [3] 74 | void RenderArea::setShape(Shape shape) 75 | { 76 | this->shape = shape; 77 | update(); 78 | } 79 | //! [3] 80 | 81 | //! [4] 82 | void RenderArea::setPen(const QPen &pen) 83 | { 84 | this->pen = pen; 85 | update(); 86 | } 87 | //! [4] 88 | 89 | //! [5] 90 | void RenderArea::setBrush(const QBrush &brush) 91 | { 92 | this->brush = brush; 93 | update(); 94 | } 95 | //! [5] 96 | 97 | //! [6] 98 | void RenderArea::setAntialiased(bool antialiased) 99 | { 100 | this->antialiased = antialiased; 101 | update(); 102 | } 103 | //! [6] 104 | 105 | //! [7] 106 | void RenderArea::setTransformed(bool transformed) 107 | { 108 | this->transformed = transformed; 109 | update(); 110 | } 111 | //! [7] 112 | 113 | //! [8] 114 | void RenderArea::paintEvent(QPaintEvent * /* event */) 115 | { 116 | static const QPoint points[4] = { 117 | QPoint(10, 80), 118 | QPoint(20, 10), 119 | QPoint(80, 30), 120 | QPoint(90, 70) 121 | }; 122 | 123 | QRect rect(10, 20, 80, 60); 124 | 125 | QPainterPath path; 126 | path.moveTo(20, 80); 127 | path.lineTo(20, 30); 128 | path.cubicTo(80, 0, 50, 50, 80, 80); 129 | 130 | int startAngle = 20 * 16; 131 | int arcLength = 120 * 16; 132 | //! [8] 133 | 134 | //! [9] 135 | QPainter painter(this); 136 | painter.setPen(pen); 137 | painter.setBrush(brush); 138 | if (antialiased) 139 | painter.setRenderHint(QPainter::Antialiasing, true); 140 | //! [9] 141 | 142 | //! [10] 143 | for (int x = 0; x < width(); x += 100) { 144 | for (int y = 0; y < height(); y += 100) { 145 | painter.save(); 146 | painter.translate(x, y); 147 | //! [10] //! [11] 148 | if (transformed) { 149 | painter.translate(50, 50); 150 | painter.rotate(60.0); 151 | painter.scale(0.6, 0.9); 152 | painter.translate(-50, -50); 153 | } 154 | //! [11] 155 | 156 | //! [12] 157 | switch (shape) { 158 | case Line: 159 | painter.drawLine(rect.bottomLeft(), rect.topRight()); 160 | break; 161 | case Points: 162 | painter.drawPoints(points, 4); 163 | break; 164 | case Polyline: 165 | painter.drawPolyline(points, 4); 166 | break; 167 | case Polygon: 168 | painter.drawPolygon(points, 4); 169 | break; 170 | case Rect: 171 | painter.drawRect(rect); 172 | break; 173 | case RoundedRect: 174 | painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize); 175 | break; 176 | case Ellipse: 177 | painter.drawEllipse(rect); 178 | break; 179 | case Arc: 180 | painter.drawArc(rect, startAngle, arcLength); 181 | break; 182 | case Chord: 183 | painter.drawChord(rect, startAngle, arcLength); 184 | break; 185 | case Pie: 186 | painter.drawPie(rect, startAngle, arcLength); 187 | break; 188 | case Path: 189 | painter.drawPath(path); 190 | break; 191 | case Text: 192 | painter.drawText(rect, Qt::AlignCenter, tr("Qt by\nDigia")); 193 | break; 194 | case Pixmap: 195 | painter.drawPixmap(10, 10, pixmap); 196 | } 197 | //! [12] //! [13] 198 | painter.restore(); 199 | } 200 | } 201 | 202 | painter.setRenderHint(QPainter::Antialiasing, false); 203 | painter.setPen(palette().dark().color()); 204 | painter.setBrush(Qt::NoBrush); 205 | painter.drawRect(QRect(0, 0, width() - 1, height() - 1)); 206 | } 207 | //! [13] 208 | -------------------------------------------------------------------------------- /qt4-project/window.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #include 42 | 43 | #include "renderarea.h" 44 | #include "window.h" 45 | 46 | //! [0] 47 | const int IdRole = Qt::UserRole; 48 | //! [0] 49 | 50 | //! [1] 51 | Window::Window() 52 | { 53 | renderArea = new RenderArea; 54 | 55 | shapeComboBox = new QComboBox; 56 | shapeComboBox->addItem(tr("Polygon"), RenderArea::Polygon); 57 | shapeComboBox->addItem(tr("Rectangle"), RenderArea::Rect); 58 | shapeComboBox->addItem(tr("Rounded Rectangle"), RenderArea::RoundedRect); 59 | shapeComboBox->addItem(tr("Ellipse"), RenderArea::Ellipse); 60 | shapeComboBox->addItem(tr("Pie"), RenderArea::Pie); 61 | shapeComboBox->addItem(tr("Chord"), RenderArea::Chord); 62 | shapeComboBox->addItem(tr("Path"), RenderArea::Path); 63 | shapeComboBox->addItem(tr("Line"), RenderArea::Line); 64 | shapeComboBox->addItem(tr("Polyline"), RenderArea::Polyline); 65 | shapeComboBox->addItem(tr("Arc"), RenderArea::Arc); 66 | shapeComboBox->addItem(tr("Points"), RenderArea::Points); 67 | shapeComboBox->addItem(tr("Text"), RenderArea::Text); 68 | shapeComboBox->addItem(tr("Pixmap"), RenderArea::Pixmap); 69 | 70 | shapeLabel = new QLabel(tr("&Shape:")); 71 | shapeLabel->setBuddy(shapeComboBox); 72 | //! [1] 73 | 74 | //! [2] 75 | penWidthSpinBox = new QSpinBox; 76 | penWidthSpinBox->setRange(0, 20); 77 | #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) 78 | penWidthSpinBox->setSpecialValueText(tr("0")); 79 | #else 80 | penWidthSpinBox->setSpecialValueText(tr("0 (cosmetic pen)")); 81 | #endif 82 | 83 | penWidthLabel = new QLabel(tr("Pen &Width:")); 84 | penWidthLabel->setBuddy(penWidthSpinBox); 85 | //! [2] 86 | 87 | //! [3] 88 | penStyleComboBox = new QComboBox; 89 | penStyleComboBox->addItem(tr("Solid"), Qt::SolidLine); 90 | penStyleComboBox->addItem(tr("Dash"), Qt::DashLine); 91 | penStyleComboBox->addItem(tr("Dot"), Qt::DotLine); 92 | penStyleComboBox->addItem(tr("Dash Dot"), Qt::DashDotLine); 93 | penStyleComboBox->addItem(tr("Dash Dot Dot"), Qt::DashDotDotLine); 94 | penStyleComboBox->addItem(tr("None"), Qt::NoPen); 95 | 96 | 97 | penStyleLabel = new QLabel(tr("&Pen Style:")); 98 | penStyleLabel->setBuddy(penStyleComboBox); 99 | 100 | penCapComboBox = new QComboBox; 101 | penCapComboBox->addItem(tr("Flat"), Qt::FlatCap); 102 | penCapComboBox->addItem(tr("Square"), Qt::SquareCap); 103 | penCapComboBox->addItem(tr("Round"), Qt::RoundCap); 104 | 105 | penCapLabel = new QLabel(tr("Pen &Cap:")); 106 | penCapLabel->setBuddy(penCapComboBox); 107 | 108 | penJoinComboBox = new QComboBox; 109 | penJoinComboBox->addItem(tr("Miter"), Qt::MiterJoin); 110 | penJoinComboBox->addItem(tr("Bevel"), Qt::BevelJoin); 111 | penJoinComboBox->addItem(tr("Round"), Qt::RoundJoin); 112 | 113 | penJoinLabel = new QLabel(tr("Pen &Join:")); 114 | penJoinLabel->setBuddy(penJoinComboBox); 115 | //! [3] 116 | 117 | //! [4] 118 | brushStyleComboBox = new QComboBox; 119 | brushStyleComboBox->addItem(tr("Linear Gradient"), 120 | Qt::LinearGradientPattern); 121 | brushStyleComboBox->addItem(tr("Radial Gradient"), 122 | Qt::RadialGradientPattern); 123 | brushStyleComboBox->addItem(tr("Conical Gradient"), 124 | Qt::ConicalGradientPattern); 125 | brushStyleComboBox->addItem(tr("Texture"), Qt::TexturePattern); 126 | brushStyleComboBox->addItem(tr("Solid"), Qt::SolidPattern); 127 | brushStyleComboBox->addItem(tr("Horizontal"), Qt::HorPattern); 128 | brushStyleComboBox->addItem(tr("Vertical"), Qt::VerPattern); 129 | brushStyleComboBox->addItem(tr("Cross"), Qt::CrossPattern); 130 | brushStyleComboBox->addItem(tr("Backward Diagonal"), Qt::BDiagPattern); 131 | brushStyleComboBox->addItem(tr("Forward Diagonal"), Qt::FDiagPattern); 132 | brushStyleComboBox->addItem(tr("Diagonal Cross"), Qt::DiagCrossPattern); 133 | brushStyleComboBox->addItem(tr("Dense 1"), Qt::Dense1Pattern); 134 | brushStyleComboBox->addItem(tr("Dense 2"), Qt::Dense2Pattern); 135 | brushStyleComboBox->addItem(tr("Dense 3"), Qt::Dense3Pattern); 136 | brushStyleComboBox->addItem(tr("Dense 4"), Qt::Dense4Pattern); 137 | brushStyleComboBox->addItem(tr("Dense 5"), Qt::Dense5Pattern); 138 | brushStyleComboBox->addItem(tr("Dense 6"), Qt::Dense6Pattern); 139 | brushStyleComboBox->addItem(tr("Dense 7"), Qt::Dense7Pattern); 140 | brushStyleComboBox->addItem(tr("None"), Qt::NoBrush); 141 | 142 | brushStyleLabel = new QLabel(tr("&Brush:")); 143 | brushStyleLabel->setBuddy(brushStyleComboBox); 144 | //! [4] 145 | 146 | //! [5] 147 | otherOptionsLabel = new QLabel(tr("Options:")); 148 | //! [5] //! [6] 149 | antialiasingCheckBox = new QCheckBox(tr("&Antialiasing")); 150 | //! [6] //! [7] 151 | transformationsCheckBox = new QCheckBox(tr("&Transformations")); 152 | //! [7] 153 | 154 | //! [8] 155 | connect(shapeComboBox, SIGNAL(activated(int)), 156 | this, SLOT(shapeChanged())); 157 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), 158 | this, SLOT(penChanged())); 159 | connect(penStyleComboBox, SIGNAL(activated(int)), 160 | this, SLOT(penChanged())); 161 | connect(penCapComboBox, SIGNAL(activated(int)), 162 | this, SLOT(penChanged())); 163 | connect(penJoinComboBox, SIGNAL(activated(int)), 164 | this, SLOT(penChanged())); 165 | connect(brushStyleComboBox, SIGNAL(activated(int)), 166 | this, SLOT(brushChanged())); 167 | connect(antialiasingCheckBox, SIGNAL(toggled(bool)), 168 | renderArea, SLOT(setAntialiased(bool))); 169 | connect(transformationsCheckBox, SIGNAL(toggled(bool)), 170 | renderArea, SLOT(setTransformed(bool))); 171 | //! [8] 172 | 173 | //! [9] 174 | QGridLayout *mainLayout = new QGridLayout; 175 | //! [9] //! [10] 176 | #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) 177 | mainLayout->setSizeConstraint(QLayout::SetNoConstraint); 178 | #endif 179 | mainLayout->setColumnStretch(0, 1); 180 | mainLayout->setColumnStretch(3, 1); 181 | mainLayout->addWidget(renderArea, 0, 0, 1, 4); 182 | mainLayout->addWidget(shapeLabel, 2, 0, Qt::AlignRight); 183 | mainLayout->addWidget(shapeComboBox, 2, 1); 184 | mainLayout->addWidget(penWidthLabel, 3, 0, Qt::AlignRight); 185 | mainLayout->addWidget(penWidthSpinBox, 3, 1); 186 | mainLayout->addWidget(penStyleLabel, 4, 0, Qt::AlignRight); 187 | mainLayout->addWidget(penStyleComboBox, 4, 1); 188 | mainLayout->addWidget(penCapLabel, 3, 2, Qt::AlignRight); 189 | mainLayout->addWidget(penCapComboBox, 3, 3); 190 | mainLayout->addWidget(penJoinLabel, 2, 2, Qt::AlignRight); 191 | mainLayout->addWidget(penJoinComboBox, 2, 3); 192 | mainLayout->addWidget(brushStyleLabel, 4, 2, Qt::AlignRight); 193 | mainLayout->addWidget(brushStyleComboBox, 4, 3); 194 | mainLayout->addWidget(otherOptionsLabel, 5, 0, Qt::AlignRight); 195 | mainLayout->addWidget(antialiasingCheckBox, 5, 1, 1, 1, Qt::AlignRight); 196 | mainLayout->addWidget(transformationsCheckBox, 5, 2, 1, 2, Qt::AlignRight); 197 | setLayout(mainLayout); 198 | 199 | shapeChanged(); 200 | penChanged(); 201 | brushChanged(); 202 | antialiasingCheckBox->setChecked(true); 203 | 204 | setWindowTitle(tr("Basic Drawing")); 205 | } 206 | //! [10] 207 | 208 | //! [11] 209 | void Window::shapeChanged() 210 | { 211 | RenderArea::Shape shape = RenderArea::Shape(shapeComboBox->itemData( 212 | shapeComboBox->currentIndex(), IdRole).toInt()); 213 | renderArea->setShape(shape); 214 | } 215 | //! [11] 216 | 217 | //! [12] 218 | void Window::penChanged() 219 | { 220 | int width = penWidthSpinBox->value(); 221 | Qt::PenStyle style = Qt::PenStyle(penStyleComboBox->itemData( 222 | penStyleComboBox->currentIndex(), IdRole).toInt()); 223 | Qt::PenCapStyle cap = Qt::PenCapStyle(penCapComboBox->itemData( 224 | penCapComboBox->currentIndex(), IdRole).toInt()); 225 | Qt::PenJoinStyle join = Qt::PenJoinStyle(penJoinComboBox->itemData( 226 | penJoinComboBox->currentIndex(), IdRole).toInt()); 227 | 228 | renderArea->setPen(QPen(Qt::blue, width, style, cap, join)); 229 | } 230 | //! [12] 231 | 232 | //! [13] 233 | void Window::brushChanged() 234 | { 235 | Qt::BrushStyle style = Qt::BrushStyle(brushStyleComboBox->itemData( 236 | //! [13] 237 | brushStyleComboBox->currentIndex(), IdRole).toInt()); 238 | 239 | //! [14] 240 | if (style == Qt::LinearGradientPattern) { 241 | QLinearGradient linearGradient(0, 0, 100, 100); 242 | linearGradient.setColorAt(0.0, Qt::white); 243 | linearGradient.setColorAt(0.2, Qt::green); 244 | linearGradient.setColorAt(1.0, Qt::black); 245 | renderArea->setBrush(linearGradient); 246 | //! [14] //! [15] 247 | } else if (style == Qt::RadialGradientPattern) { 248 | QRadialGradient radialGradient(50, 50, 50, 70, 70); 249 | radialGradient.setColorAt(0.0, Qt::white); 250 | radialGradient.setColorAt(0.2, Qt::green); 251 | radialGradient.setColorAt(1.0, Qt::black); 252 | renderArea->setBrush(radialGradient); 253 | } else if (style == Qt::ConicalGradientPattern) { 254 | QConicalGradient conicalGradient(50, 50, 150); 255 | conicalGradient.setColorAt(0.0, Qt::white); 256 | conicalGradient.setColorAt(0.2, Qt::green); 257 | conicalGradient.setColorAt(1.0, Qt::black); 258 | renderArea->setBrush(conicalGradient); 259 | //! [15] //! [16] 260 | } else if (style == Qt::TexturePattern) { 261 | renderArea->setBrush(QBrush(QPixmap(":/images/brick.png"))); 262 | //! [16] //! [17] 263 | } else { 264 | renderArea->setBrush(QBrush(Qt::green, style)); 265 | } 266 | } 267 | //! [17] 268 | --------------------------------------------------------------------------------