Skip to content

Commit e11c197

Browse files
committed
added exercise06 for chapter12
1 parent 6750bac commit e11c197

18 files changed

+2693
-0
lines changed

Chapter12/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,6 @@ Define a class `Immobile_Circle`, which is just like `Circle` but can't be moved
114114

115115
## [Exercise 5](exercises/05)
116116
Define a `Striped_rectangle` where instead of fill, the rectangle is "filled" by drawing one-pixel-wide horizontal lines across the inside of the rectangle (say, draw every second line like that). You may have to play with the width of lines and the line spacing to get a pattern you like.
117+
118+
## [Exercise 6](exercises/06)
119+
Define a `Striped_circle` using the technique from `Striped_rectangle`.

Chapter12/exercises/06/CMakeLists.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(Programming_Qt VERSION 0.1 LANGUAGES CXX)
4+
5+
set(CMAKE_AUTOUIC ON)
6+
set(CMAKE_AUTOMOC ON)
7+
set(CMAKE_AUTORCC ON)
8+
9+
set(CMAKE_CXX_STANDARD 20)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
12+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
13+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
14+
15+
set(PROJECT_SOURCES
16+
main.cpp
17+
PPP/Window.h
18+
PPP/Graph.h
19+
PPP/GUI.h
20+
PPP/Simple_window.h
21+
PPP/Point.h
22+
PPP/std_lib_facilities.h
23+
Window.cpp
24+
Graph.cpp
25+
PPP/Image_private.h
26+
GUI.cpp
27+
PPP/GUI_private.h
28+
Simple_window.cpp
29+
Colormap.cpp
30+
)
31+
32+
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
33+
qt_add_executable(Programming_Qt
34+
MANUAL_FINALIZATION
35+
${PROJECT_SOURCES}
36+
)
37+
38+
# Define target properties for Android with Qt 6 as:
39+
# set_property(TARGET Programming_Qt APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
40+
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
41+
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
42+
else()
43+
if(ANDROID)
44+
add_library(Programming_Qt SHARED
45+
${PROJECT_SOURCES}
46+
)
47+
# Define properties for Android with Qt 5 after find_package() calls as:
48+
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
49+
else()
50+
add_executable(Programming_Qt
51+
${PROJECT_SOURCES}
52+
)
53+
endif()
54+
endif()
55+
56+
target_link_libraries(Programming_Qt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
57+
target_include_directories(Programming_Qt PRIVATE .)
58+
59+
set_target_properties(Programming_Qt PROPERTIES
60+
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
61+
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
62+
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
63+
MACOSX_BUNDLE TRUE
64+
WIN32_EXECUTABLE TRUE
65+
)
66+
67+
if(MSVC)
68+
target_compile_options(Programming_Qt PRIVATE /EHsc /W4 /WX)
69+
else()
70+
target_compile_options(Programming_Qt PRIVATE -Wall -Wextra -Wpedantic -Werror)
71+
endif()
72+
73+
if (EMSCRIPTEN)
74+
target_link_options(Programming_Qt PUBLIC -sASYNCIFY -Os)
75+
endif()
76+
77+
install(TARGETS Programming_Qt
78+
BUNDLE DESTINATION .
79+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
80+
81+
if(QT_VERSION_MAJOR EQUAL 6)
82+
qt_finalize_executable(Programming_Qt)
83+
endif()

Chapter12/exercises/06/Colormap.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <QColor>
2+
#include <PPP/Image_private.h>
3+
4+
static QColor paletteColorMap[]
5+
= {{0, 0, 0}, {255, 0, 0}, {0, 255, 0}, {255, 255, 0}, {0, 0, 255},
6+
{255, 0, 255}, {0, 255, 255}, {255, 255, 255}, {85, 85, 85}, {198, 113, 113},
7+
{113, 198, 113}, {142, 142, 56}, {113, 113, 198}, {142, 56, 142}, {56, 142, 142},
8+
{0, 0, 128}, {168, 168, 152}, {232, 232, 216}, {104, 104, 88}, {152, 168, 168},
9+
{216, 232, 232}, {88, 104, 104}, {156, 156, 168}, {220, 220, 232}, {92, 92, 104},
10+
{156, 168, 156}, {220, 232, 220}, {92, 104, 92}, {144, 144, 144}, {192, 192, 192},
11+
{80, 80, 80}, {160, 160, 160}, {0, 0, 0}, {13, 13, 13}, {26, 26, 26},
12+
{38, 38, 38}, {49, 49, 49}, {61, 61, 61}, {72, 72, 72}, {85, 85, 85},
13+
{95, 95, 95}, {106, 106, 106}, {117, 117, 117}, {128, 128, 128}, {138, 138, 138},
14+
{149, 149, 149}, {160, 160, 160}, {170, 170, 170}, {181, 181, 181}, {192, 192, 192},
15+
{203, 203, 203}, {213, 213, 213}, {224, 224, 224}, {234, 234, 234}, {245, 245, 245},
16+
{255, 255, 255}, {0, 0, 0}, {0, 36, 0}, {0, 72, 0}, {0, 109, 0},
17+
{0, 145, 0}, {0, 182, 0}, {0, 218, 0}, {0, 255, 0}, {63, 0, 0},
18+
{63, 36, 0}, {63, 72, 0}, {63, 109, 0}, {63, 145, 0}, {63, 182, 0},
19+
{63, 218, 0}, {63, 255, 0}, {127, 0, 0}, {127, 36, 0}, {127, 72, 0},
20+
{127, 109, 0}, {127, 145, 0}, {127, 182, 0}, {127, 218, 0}, {127, 255, 0},
21+
{191, 0, 0}, {191, 36, 0}, {191, 72, 0}, {191, 109, 0}, {191, 145, 0},
22+
{191, 182, 0}, {191, 218, 0}, {191, 255, 0}, {255, 0, 0}, {255, 36, 0},
23+
{255, 72, 0}, {255, 109, 0}, {255, 145, 0}, {255, 182, 0}, {255, 218, 0},
24+
{255, 255, 0}, {0, 0, 63}, {0, 36, 63}, {0, 72, 63}, {0, 109, 63},
25+
{0, 145, 63}, {0, 182, 63}, {0, 218, 63}, {0, 255, 63}, {63, 0, 63},
26+
{63, 36, 63}, {63, 72, 63}, {63, 109, 63}, {63, 145, 63}, {63, 182, 63},
27+
{63, 218, 63}, {63, 255, 63}, {127, 0, 63}, {127, 36, 63}, {127, 72, 63},
28+
{127, 109, 63}, {127, 145, 63}, {127, 182, 63}, {127, 218, 63}, {127, 255, 63},
29+
{191, 0, 63}, {191, 36, 63}, {191, 72, 63}, {191, 109, 63}, {191, 145, 63},
30+
{191, 182, 63}, {191, 218, 63}, {191, 255, 63}, {255, 0, 63}, {255, 36, 63},
31+
{255, 72, 63}, {255, 109, 63}, {255, 145, 63}, {255, 182, 63}, {255, 218, 63},
32+
{255, 255, 63}, {0, 0, 127}, {0, 36, 127}, {0, 72, 127}, {0, 109, 127},
33+
{0, 145, 127}, {0, 182, 127}, {0, 218, 127}, {0, 255, 127}, {63, 0, 127},
34+
{63, 36, 127}, {63, 72, 127}, {63, 109, 127}, {63, 145, 127}, {63, 182, 127},
35+
{63, 218, 127}, {63, 255, 127}, {127, 0, 127}, {127, 36, 127}, {127, 72, 127},
36+
{127, 109, 127}, {127, 145, 127}, {127, 182, 127}, {127, 218, 127}, {127, 255, 127},
37+
{191, 0, 127}, {191, 36, 127}, {191, 72, 127}, {191, 109, 127}, {191, 145, 127},
38+
{191, 182, 127}, {191, 218, 127}, {191, 255, 127}, {255, 0, 127}, {255, 36, 127},
39+
{255, 72, 127}, {255, 109, 127}, {255, 145, 127}, {255, 182, 127}, {255, 218, 127},
40+
{255, 255, 127}, {0, 0, 191}, {0, 36, 191}, {0, 72, 191}, {0, 109, 191},
41+
{0, 145, 191}, {0, 182, 191}, {0, 218, 191}, {0, 255, 191}, {63, 0, 191},
42+
{63, 36, 191}, {63, 72, 191}, {63, 109, 191}, {63, 145, 191}, {63, 182, 191},
43+
{63, 218, 191}, {63, 255, 191}, {127, 0, 191}, {127, 36, 191}, {127, 72, 191},
44+
{127, 109, 191}, {127, 145, 191}, {127, 182, 191}, {127, 218, 191}, {127, 255, 191},
45+
{191, 0, 191}, {191, 36, 191}, {191, 72, 191}, {191, 109, 191}, {191, 145, 191},
46+
{191, 182, 191}, {191, 218, 191}, {191, 255, 191}, {255, 0, 191}, {255, 36, 191},
47+
{255, 72, 191}, {255, 109, 191}, {255, 145, 191}, {255, 182, 191}, {255, 218, 191},
48+
{255, 255, 191}, {0, 0, 255}, {0, 36, 255}, {0, 72, 255}, {0, 109, 255},
49+
{0, 145, 255}, {0, 182, 255}, {0, 218, 255}, {0, 255, 255}, {63, 0, 255},
50+
{63, 36, 255}, {63, 72, 255}, {63, 109, 255}, {63, 145, 255}, {63, 182, 255},
51+
{63, 218, 255}, {63, 255, 255}, {127, 0, 255}, {127, 36, 255}, {127, 72, 255},
52+
{127, 109, 255}, {127, 145, 255}, {127, 182, 255}, {127, 218, 255}, {127, 255, 255},
53+
{191, 0, 255}, {191, 36, 255}, {191, 72, 255}, {191, 109, 255}, {191, 145, 255},
54+
{191, 182, 255}, {191, 218, 255}, {191, 255, 255}, {255, 0, 255}, {255, 36, 255},
55+
{255, 72, 255}, {255, 109, 255}, {255, 145, 255}, {255, 182, 255}, {255, 218, 255},
56+
{255, 255, 255}};
57+
58+
namespace Graph_lib {
59+
QColor mapPaletteColor(int rawColor)
60+
{
61+
return paletteColorMap[rawColor % 256];
62+
}
63+
64+
} // namespace Graph_lib

0 commit comments

Comments
 (0)