├── README.md ├── refrence ├── bathroom headlines.txt ├── sample image │ ├── bathroom (1).jpg │ ├── bathroom (10).jpg │ ├── bathroom (11).jpg │ ├── bathroom (12).jpg │ ├── bathroom (13).jpg │ ├── bathroom (14).jpg │ ├── bathroom (15).jpg │ ├── bathroom (16).jpg │ ├── bathroom (17).jpg │ ├── bathroom (18).jpg │ ├── bathroom (19).jpg │ ├── bathroom (2).jpg │ ├── bathroom (20).jpg │ ├── bathroom (3).jpg │ ├── bathroom (4).jpg │ ├── bathroom (5).jpg │ ├── bathroom (6).jpg │ ├── bathroom (7).jpg │ ├── bathroom (8).jpg │ └── bathroom (9).jpg └── styles │ ├── images │ ├── woodbackground.png │ └── woodbutton.png │ ├── main.cpp │ ├── norwegianwoodstyle.cpp │ ├── norwegianwoodstyle.h │ ├── styles.pro │ ├── styles.pro.user │ ├── styles.qrc │ ├── widgetgallery.cpp │ └── widgetgallery.h └── src └── image-processing ├── CMainTabDialog.cpp ├── CMainTabDialog.h ├── UI ├── CCustomizeTab.cpp ├── CCustomizeTab.h ├── CFileTab.cpp ├── CFileTab.h ├── CMergeThread.cpp ├── CMergeThread.h ├── COutputTab.cpp ├── COutputTab.h ├── CTextTab.cpp └── CTextTab.h ├── global.h ├── images ├── Untitled-1.png ├── template.png ├── template1.png ├── template2.png ├── template3.png ├── template4.png ├── template5.png ├── template6.png ├── template7.png ├── template8.png ├── woodbackground.png └── woodbutton.png ├── main.cpp ├── norwegianwoodstyle.cpp ├── norwegianwoodstyle.h ├── styles.pro ├── styles.qrc ├── widgetgallery.cpp └── widgetgallery.h /README.md: -------------------------------------------------------------------------------- 1 | # Image-merge 2 | -------------------------------------------------------------------------------- /refrence/sample image/bathroom (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (1).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (10).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (10).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (11).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (11).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (12).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (12).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (13).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (13).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (14).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (14).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (15).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (15).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (16).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (16).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (17).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (17).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (18).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (18).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (19).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (19).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (2).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (2).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (20).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (20).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (3).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (3).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (4).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (4).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (5).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (5).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (6).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (6).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (7).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (7).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (8).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (8).jpg -------------------------------------------------------------------------------- /refrence/sample image/bathroom (9).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/sample image/bathroom (9).jpg -------------------------------------------------------------------------------- /refrence/styles/images/woodbackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/styles/images/woodbackground.png -------------------------------------------------------------------------------- /refrence/styles/images/woodbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/refrence/styles/images/woodbutton.png -------------------------------------------------------------------------------- /refrence/styles/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "widgetgallery.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | Q_INIT_RESOURCE(styles); 8 | 9 | QApplication app(argc, argv); 10 | WidgetGallery gallery; 11 | gallery.show(); 12 | return app.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /refrence/styles/norwegianwoodstyle.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include 52 | 53 | #include "norwegianwoodstyle.h" 54 | 55 | NorwegianWoodStyle::NorwegianWoodStyle() : 56 | QProxyStyle(QStyleFactory::create("windows")) 57 | { 58 | } 59 | 60 | //! [0] 61 | void NorwegianWoodStyle::polish(QPalette &palette) 62 | { 63 | QColor brown(212, 140, 95); 64 | QColor beige(236, 182, 120); 65 | QColor slightlyOpaqueBlack(0, 0, 0, 63); 66 | 67 | QPixmap backgroundImage(":/images/woodbackground.png"); 68 | QPixmap buttonImage(":/images/woodbutton.png"); 69 | QPixmap midImage = buttonImage; 70 | 71 | QPainter painter; 72 | painter.begin(&midImage); 73 | painter.setPen(Qt::NoPen); 74 | painter.fillRect(midImage.rect(), slightlyOpaqueBlack); 75 | painter.end(); 76 | //! [0] 77 | 78 | //! [1] 79 | palette = QPalette(brown); 80 | 81 | palette.setBrush(QPalette::BrightText, Qt::white); 82 | palette.setBrush(QPalette::Base, beige); 83 | palette.setBrush(QPalette::Highlight, Qt::darkGreen); 84 | setTexture(palette, QPalette::Button, buttonImage); 85 | setTexture(palette, QPalette::Mid, midImage); 86 | setTexture(palette, QPalette::Window, backgroundImage); 87 | 88 | QBrush brush = palette.background(); 89 | brush.setColor(brush.color().dark()); 90 | 91 | palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush); 92 | palette.setBrush(QPalette::Disabled, QPalette::Text, brush); 93 | palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush); 94 | palette.setBrush(QPalette::Disabled, QPalette::Base, brush); 95 | palette.setBrush(QPalette::Disabled, QPalette::Button, brush); 96 | palette.setBrush(QPalette::Disabled, QPalette::Mid, brush); 97 | } 98 | //! [1] 99 | 100 | //! [3] 101 | void NorwegianWoodStyle::polish(QWidget *widget) 102 | //! [3] //! [4] 103 | { 104 | if (qobject_cast(widget) 105 | || qobject_cast(widget)) 106 | widget->setAttribute(Qt::WA_Hover, true); 107 | } 108 | //! [4] 109 | 110 | //! [5] 111 | void NorwegianWoodStyle::unpolish(QWidget *widget) 112 | //! [5] //! [6] 113 | { 114 | if (qobject_cast(widget) 115 | || qobject_cast(widget)) 116 | widget->setAttribute(Qt::WA_Hover, false); 117 | } 118 | //! [6] 119 | 120 | //! [7] 121 | int NorwegianWoodStyle::pixelMetric(PixelMetric metric, 122 | //! [7] //! [8] 123 | const QStyleOption *option, 124 | const QWidget *widget) const 125 | { 126 | switch (metric) { 127 | case PM_ComboBoxFrameWidth: 128 | return 8; 129 | case PM_ScrollBarExtent: 130 | return QProxyStyle::pixelMetric(metric, option, widget) + 4; 131 | default: 132 | return QProxyStyle::pixelMetric(metric, option, widget); 133 | } 134 | } 135 | //! [8] 136 | 137 | //! [9] 138 | int NorwegianWoodStyle::styleHint(StyleHint hint, const QStyleOption *option, 139 | //! [9] //! [10] 140 | const QWidget *widget, 141 | QStyleHintReturn *returnData) const 142 | { 143 | switch (hint) { 144 | case SH_DitherDisabledText: 145 | return int(false); 146 | case SH_EtchDisabledText: 147 | return int(true); 148 | default: 149 | return QProxyStyle::styleHint(hint, option, widget, returnData); 150 | } 151 | } 152 | //! [10] 153 | 154 | //! [11] 155 | void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element, 156 | //! [11] //! [12] 157 | const QStyleOption *option, 158 | QPainter *painter, 159 | const QWidget *widget) const 160 | { 161 | switch (element) { 162 | case PE_PanelButtonCommand: 163 | { 164 | int delta = (option->state & State_MouseOver) ? 64 : 0; 165 | QColor slightlyOpaqueBlack(0, 0, 0, 63); 166 | QColor semiTransparentWhite(255, 255, 255, 127 + delta); 167 | QColor semiTransparentBlack(0, 0, 0, 127 - delta); 168 | 169 | int x, y, width, height; 170 | option->rect.getRect(&x, &y, &width, &height); 171 | //! [12] 172 | 173 | //! [13] 174 | QPainterPath roundRect = roundRectPath(option->rect); 175 | //! [13] //! [14] 176 | int radius = qMin(width, height) / 2; 177 | //! [14] 178 | 179 | //! [15] 180 | QBrush brush; 181 | //! [15] //! [16] 182 | bool darker; 183 | 184 | const QStyleOptionButton *buttonOption = 185 | qstyleoption_cast(option); 186 | if (buttonOption 187 | && (buttonOption->features & QStyleOptionButton::Flat)) { 188 | brush = option->palette.background(); 189 | darker = (option->state & (State_Sunken | State_On)); 190 | } else { 191 | if (option->state & (State_Sunken | State_On)) { 192 | brush = option->palette.mid(); 193 | darker = !(option->state & State_Sunken); 194 | } else { 195 | brush = option->palette.button(); 196 | darker = false; 197 | //! [16] //! [17] 198 | } 199 | //! [17] //! [18] 200 | } 201 | //! [18] 202 | 203 | //! [19] 204 | painter->save(); 205 | //! [19] //! [20] 206 | painter->setRenderHint(QPainter::Antialiasing, true); 207 | //! [20] //! [21] 208 | painter->fillPath(roundRect, brush); 209 | //! [21] //! [22] 210 | if (darker) 211 | //! [22] //! [23] 212 | painter->fillPath(roundRect, slightlyOpaqueBlack); 213 | //! [23] 214 | 215 | //! [24] 216 | int penWidth; 217 | //! [24] //! [25] 218 | if (radius < 10) 219 | penWidth = 3; 220 | else if (radius < 20) 221 | penWidth = 5; 222 | else 223 | penWidth = 7; 224 | 225 | QPen topPen(semiTransparentWhite, penWidth); 226 | QPen bottomPen(semiTransparentBlack, penWidth); 227 | 228 | if (option->state & (State_Sunken | State_On)) 229 | qSwap(topPen, bottomPen); 230 | //! [25] 231 | 232 | //! [26] 233 | int x1 = x; 234 | int x2 = x + radius; 235 | int x3 = x + width - radius; 236 | int x4 = x + width; 237 | 238 | if (option->direction == Qt::RightToLeft) { 239 | qSwap(x1, x4); 240 | qSwap(x2, x3); 241 | } 242 | 243 | QPolygon topHalf; 244 | topHalf << QPoint(x1, y) 245 | << QPoint(x4, y) 246 | << QPoint(x3, y + radius) 247 | << QPoint(x2, y + height - radius) 248 | << QPoint(x1, y + height); 249 | 250 | painter->setClipPath(roundRect); 251 | painter->setClipRegion(topHalf, Qt::IntersectClip); 252 | painter->setPen(topPen); 253 | painter->drawPath(roundRect); 254 | //! [26] //! [32] 255 | 256 | QPolygon bottomHalf = topHalf; 257 | bottomHalf[0] = QPoint(x4, y + height); 258 | 259 | painter->setClipPath(roundRect); 260 | painter->setClipRegion(bottomHalf, Qt::IntersectClip); 261 | painter->setPen(bottomPen); 262 | painter->drawPath(roundRect); 263 | 264 | painter->setPen(option->palette.foreground().color()); 265 | painter->setClipping(false); 266 | painter->drawPath(roundRect); 267 | 268 | painter->restore(); 269 | } 270 | break; 271 | //! [32] //! [33] 272 | default: 273 | //! [33] //! [34] 274 | QProxyStyle::drawPrimitive(element, option, painter, widget); 275 | } 276 | } 277 | //! [34] 278 | 279 | //! [35] 280 | void NorwegianWoodStyle::drawControl(ControlElement element, 281 | //! [35] //! [36] 282 | const QStyleOption *option, 283 | QPainter *painter, 284 | const QWidget *widget) const 285 | { 286 | switch (element) { 287 | case CE_PushButtonLabel: 288 | { 289 | QStyleOptionButton myButtonOption; 290 | const QStyleOptionButton *buttonOption = 291 | qstyleoption_cast(option); 292 | if (buttonOption) { 293 | myButtonOption = *buttonOption; 294 | if (myButtonOption.palette.currentColorGroup() 295 | != QPalette::Disabled) { 296 | if (myButtonOption.state & (State_Sunken | State_On)) { 297 | myButtonOption.palette.setBrush(QPalette::ButtonText, 298 | myButtonOption.palette.brightText()); 299 | } 300 | } 301 | } 302 | QProxyStyle::drawControl(element, &myButtonOption, painter, widget); 303 | } 304 | break; 305 | default: 306 | QProxyStyle::drawControl(element, option, painter, widget); 307 | } 308 | } 309 | //! [36] 310 | 311 | //! [37] 312 | void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role, 313 | //! [37] //! [38] 314 | const QPixmap &pixmap) 315 | { 316 | for (int i = 0; i < QPalette::NColorGroups; ++i) { 317 | QColor color = palette.brush(QPalette::ColorGroup(i), role).color(); 318 | palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap)); 319 | } 320 | } 321 | //! [38] 322 | 323 | //! [39] 324 | QPainterPath NorwegianWoodStyle::roundRectPath(const QRect &rect) 325 | //! [39] //! [40] 326 | { 327 | int radius = qMin(rect.width(), rect.height()) / 2; 328 | int diam = 2 * radius; 329 | 330 | int x1, y1, x2, y2; 331 | rect.getCoords(&x1, &y1, &x2, &y2); 332 | 333 | QPainterPath path; 334 | path.moveTo(x2, y1 + radius); 335 | path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0); 336 | path.lineTo(x1 + radius, y1); 337 | path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0); 338 | path.lineTo(x1, y2 - radius); 339 | path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0); 340 | path.lineTo(x1 + radius, y2); 341 | path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0); 342 | path.closeSubpath(); 343 | return path; 344 | } 345 | //! [40] 346 | -------------------------------------------------------------------------------- /refrence/styles/norwegianwoodstyle.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef NORWEGIANWOODSTYLE_H 52 | #define NORWEGIANWOODSTYLE_H 53 | 54 | #include 55 | #include 56 | 57 | QT_BEGIN_NAMESPACE 58 | class QPainterPath; 59 | QT_END_NAMESPACE 60 | 61 | //! [0] 62 | class NorwegianWoodStyle : public QProxyStyle 63 | { 64 | Q_OBJECT 65 | 66 | public: 67 | NorwegianWoodStyle(); 68 | 69 | void polish(QPalette &palette) override; 70 | void polish(QWidget *widget) override; 71 | void unpolish(QWidget *widget) override; 72 | int pixelMetric(PixelMetric metric, const QStyleOption *option, 73 | const QWidget *widget) const override; 74 | int styleHint(StyleHint hint, const QStyleOption *option, 75 | const QWidget *widget, QStyleHintReturn *returnData) const override; 76 | void drawPrimitive(PrimitiveElement element, const QStyleOption *option, 77 | QPainter *painter, const QWidget *widget) const override; 78 | void drawControl(ControlElement control, const QStyleOption *option, 79 | QPainter *painter, const QWidget *widget) const override; 80 | 81 | private: 82 | static void setTexture(QPalette &palette, QPalette::ColorRole role, 83 | const QPixmap &pixmap); 84 | static QPainterPath roundRectPath(const QRect &rect); 85 | }; 86 | //! [0] 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /refrence/styles/styles.pro: -------------------------------------------------------------------------------- 1 | QT += widgets 2 | 3 | HEADERS = norwegianwoodstyle.h \ 4 | widgetgallery.h 5 | SOURCES = main.cpp \ 6 | norwegianwoodstyle.cpp \ 7 | widgetgallery.cpp 8 | RESOURCES = styles.qrc 9 | 10 | # install 11 | target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/styles 12 | INSTALLS += target 13 | -------------------------------------------------------------------------------- /refrence/styles/styles.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {85721dbb-a2c4-4198-b6e5-c175fa24a25e} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | Desktop Qt 5.9.2 MinGW 32bit 63 | Desktop Qt 5.9.2 MinGW 32bit 64 | qt.592.win32_mingw53_kit 65 | 0 66 | 0 67 | 0 68 | 69 | C:/Qt/Qt5.9.2/Examples/Qt-5.9.2/widgets/widgets/build-styles-Desktop_Qt_5_9_2_MinGW_32bit-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | false 89 | 90 | 91 | 92 | 2 93 | Build 94 | 95 | ProjectExplorer.BuildSteps.Build 96 | 97 | 98 | 99 | true 100 | Make 101 | 102 | Qt4ProjectManager.MakeStep 103 | 104 | true 105 | clean 106 | 107 | 108 | 1 109 | Clean 110 | 111 | ProjectExplorer.BuildSteps.Clean 112 | 113 | 2 114 | false 115 | 116 | Debug 117 | 118 | Qt4ProjectManager.Qt4BuildConfiguration 119 | 2 120 | true 121 | 122 | 123 | C:/Qt/Qt5.9.2/Examples/Qt-5.9.2/widgets/widgets/build-styles-Desktop_Qt_5_9_2_MinGW_32bit-Release 124 | 125 | 126 | true 127 | qmake 128 | 129 | QtProjectManager.QMakeBuildStep 130 | false 131 | 132 | false 133 | false 134 | false 135 | 136 | 137 | true 138 | Make 139 | 140 | Qt4ProjectManager.MakeStep 141 | 142 | false 143 | 144 | 145 | 146 | 2 147 | Build 148 | 149 | ProjectExplorer.BuildSteps.Build 150 | 151 | 152 | 153 | true 154 | Make 155 | 156 | Qt4ProjectManager.MakeStep 157 | 158 | true 159 | clean 160 | 161 | 162 | 1 163 | Clean 164 | 165 | ProjectExplorer.BuildSteps.Clean 166 | 167 | 2 168 | false 169 | 170 | Release 171 | 172 | Qt4ProjectManager.Qt4BuildConfiguration 173 | 0 174 | true 175 | 176 | 177 | C:/Qt/Qt5.9.2/Examples/Qt-5.9.2/widgets/widgets/build-styles-Desktop_Qt_5_9_2_MinGW_32bit-Profile 178 | 179 | 180 | true 181 | qmake 182 | 183 | QtProjectManager.QMakeBuildStep 184 | true 185 | 186 | false 187 | true 188 | false 189 | 190 | 191 | true 192 | Make 193 | 194 | Qt4ProjectManager.MakeStep 195 | 196 | false 197 | 198 | 199 | 200 | 2 201 | Build 202 | 203 | ProjectExplorer.BuildSteps.Build 204 | 205 | 206 | 207 | true 208 | Make 209 | 210 | Qt4ProjectManager.MakeStep 211 | 212 | true 213 | clean 214 | 215 | 216 | 1 217 | Clean 218 | 219 | ProjectExplorer.BuildSteps.Clean 220 | 221 | 2 222 | false 223 | 224 | Profile 225 | 226 | Qt4ProjectManager.Qt4BuildConfiguration 227 | 0 228 | true 229 | 230 | 3 231 | 232 | 233 | 0 234 | Deploy 235 | 236 | ProjectExplorer.BuildSteps.Deploy 237 | 238 | 1 239 | Deploy locally 240 | 241 | ProjectExplorer.DefaultDeployConfiguration 242 | 243 | 1 244 | 245 | 246 | false 247 | false 248 | 1000 249 | 250 | true 251 | 252 | false 253 | false 254 | false 255 | false 256 | true 257 | 0.01 258 | 10 259 | true 260 | 1 261 | 25 262 | 263 | 1 264 | true 265 | false 266 | true 267 | valgrind 268 | 269 | 0 270 | 1 271 | 2 272 | 3 273 | 4 274 | 5 275 | 6 276 | 7 277 | 8 278 | 9 279 | 10 280 | 11 281 | 12 282 | 13 283 | 14 284 | 285 | 2 286 | 287 | styles 288 | 289 | Qt4ProjectManager.Qt4RunConfiguration:C:/Qt/Qt5.9.2/Examples/Qt-5.9.2/widgets/widgets/styles/styles.pro 290 | true 291 | 292 | styles.pro 293 | false 294 | 295 | C:/Qt/Qt5.9.2/Examples/Qt-5.9.2/widgets/widgets/build-styles-Desktop_Qt_5_9_2_MinGW_32bit-Debug 296 | 3768 297 | false 298 | true 299 | false 300 | false 301 | true 302 | 303 | 1 304 | 305 | 306 | 307 | ProjectExplorer.Project.TargetCount 308 | 1 309 | 310 | 311 | ProjectExplorer.Project.Updater.FileVersion 312 | 18 313 | 314 | 315 | Version 316 | 18 317 | 318 | 319 | -------------------------------------------------------------------------------- /refrence/styles/styles.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/woodbutton.png 4 | images/woodbackground.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /refrence/styles/widgetgallery.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include 52 | 53 | #include "norwegianwoodstyle.h" 54 | #include "widgetgallery.h" 55 | 56 | //! [0] 57 | WidgetGallery::WidgetGallery(QWidget *parent) 58 | : QDialog(parent) 59 | { 60 | originalPalette = QApplication::palette(); 61 | 62 | styleComboBox = new QComboBox; 63 | styleComboBox->addItem("NorwegianWood"); 64 | styleComboBox->addItems(QStyleFactory::keys()); 65 | 66 | styleLabel = new QLabel(tr("&Style:")); 67 | styleLabel->setBuddy(styleComboBox); 68 | 69 | useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette")); 70 | useStylePaletteCheckBox->setChecked(true); 71 | 72 | disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets")); 73 | 74 | createTopLeftGroupBox(); 75 | createTopRightGroupBox(); 76 | createBottomLeftTabWidget(); 77 | createBottomRightGroupBox(); 78 | createProgressBar(); 79 | //! [0] 80 | 81 | //! [1] 82 | connect(styleComboBox, SIGNAL(activated(QString)), 83 | //! [1] //! [2] 84 | this, SLOT(changeStyle(QString))); 85 | connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)), 86 | this, SLOT(changePalette())); 87 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 88 | topLeftGroupBox, SLOT(setDisabled(bool))); 89 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 90 | topRightGroupBox, SLOT(setDisabled(bool))); 91 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 92 | bottomLeftTabWidget, SLOT(setDisabled(bool))); 93 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 94 | bottomRightGroupBox, SLOT(setDisabled(bool))); 95 | //! [2] 96 | 97 | //! [3] 98 | QHBoxLayout *topLayout = new QHBoxLayout; 99 | //! [3] //! [4] 100 | topLayout->addWidget(styleLabel); 101 | topLayout->addWidget(styleComboBox); 102 | topLayout->addStretch(1); 103 | topLayout->addWidget(useStylePaletteCheckBox); 104 | topLayout->addWidget(disableWidgetsCheckBox); 105 | 106 | QGridLayout *mainLayout = new QGridLayout; 107 | mainLayout->addLayout(topLayout, 0, 0, 1, 2); 108 | mainLayout->addWidget(topLeftGroupBox, 1, 0); 109 | mainLayout->addWidget(topRightGroupBox, 1, 1); 110 | mainLayout->addWidget(bottomLeftTabWidget, 2, 0); 111 | mainLayout->addWidget(bottomRightGroupBox, 2, 1); 112 | mainLayout->addWidget(progressBar, 3, 0, 1, 2); 113 | mainLayout->setRowStretch(1, 1); 114 | mainLayout->setRowStretch(2, 1); 115 | mainLayout->setColumnStretch(0, 1); 116 | mainLayout->setColumnStretch(1, 1); 117 | setLayout(mainLayout); 118 | 119 | setWindowTitle(tr("Styles")); 120 | changeStyle("NorwegianWood"); 121 | } 122 | //! [4] 123 | 124 | //! [5] 125 | void WidgetGallery::changeStyle(const QString &styleName) 126 | //! [5] //! [6] 127 | { 128 | if (styleName == "NorwegianWood") { 129 | QApplication::setStyle(new NorwegianWoodStyle); 130 | } else { 131 | QApplication::setStyle(QStyleFactory::create(styleName)); 132 | } 133 | changePalette(); 134 | } 135 | //! [6] 136 | 137 | //! [7] 138 | void WidgetGallery::changePalette() 139 | //! [7] //! [8] 140 | { 141 | if (useStylePaletteCheckBox->isChecked()) 142 | QApplication::setPalette(QApplication::style()->standardPalette()); 143 | else 144 | QApplication::setPalette(originalPalette); 145 | } 146 | //! [8] 147 | 148 | //! [9] 149 | void WidgetGallery::advanceProgressBar() 150 | //! [9] //! [10] 151 | { 152 | int curVal = progressBar->value(); 153 | int maxVal = progressBar->maximum(); 154 | progressBar->setValue(curVal + (maxVal - curVal) / 100); 155 | } 156 | //! [10] 157 | 158 | //! [11] 159 | void WidgetGallery::createTopLeftGroupBox() 160 | //! [11] //! [12] 161 | { 162 | topLeftGroupBox = new QGroupBox(tr("Group 1")); 163 | 164 | radioButton1 = new QRadioButton(tr("Radio button 1")); 165 | radioButton2 = new QRadioButton(tr("Radio button 2")); 166 | radioButton3 = new QRadioButton(tr("Radio button 3")); 167 | radioButton1->setChecked(true); 168 | 169 | checkBox = new QCheckBox(tr("Tri-state check box")); 170 | checkBox->setTristate(true); 171 | checkBox->setCheckState(Qt::PartiallyChecked); 172 | 173 | QVBoxLayout *layout = new QVBoxLayout; 174 | layout->addWidget(radioButton1); 175 | layout->addWidget(radioButton2); 176 | layout->addWidget(radioButton3); 177 | layout->addWidget(checkBox); 178 | layout->addStretch(1); 179 | topLeftGroupBox->setLayout(layout); 180 | } 181 | //! [12] 182 | 183 | void WidgetGallery::createTopRightGroupBox() 184 | { 185 | topRightGroupBox = new QGroupBox(tr("Group 2")); 186 | 187 | defaultPushButton = new QPushButton(tr("Default Push Button")); 188 | defaultPushButton->setDefault(true); 189 | 190 | togglePushButton = new QPushButton(tr("Toggle Push Button")); 191 | togglePushButton->setCheckable(true); 192 | togglePushButton->setChecked(true); 193 | 194 | flatPushButton = new QPushButton(tr("Flat Push Button")); 195 | flatPushButton->setFlat(true); 196 | 197 | QVBoxLayout *layout = new QVBoxLayout; 198 | layout->addWidget(defaultPushButton); 199 | layout->addWidget(togglePushButton); 200 | layout->addWidget(flatPushButton); 201 | layout->addStretch(1); 202 | topRightGroupBox->setLayout(layout); 203 | } 204 | 205 | void WidgetGallery::createBottomLeftTabWidget() 206 | { 207 | bottomLeftTabWidget = new QTabWidget; 208 | bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred, 209 | QSizePolicy::Ignored); 210 | 211 | QWidget *tab1 = new QWidget; 212 | tableWidget = new QTableWidget(10, 10); 213 | 214 | QHBoxLayout *tab1hbox = new QHBoxLayout; 215 | tab1hbox->setMargin(5); 216 | tab1hbox->addWidget(tableWidget); 217 | tab1->setLayout(tab1hbox); 218 | 219 | QWidget *tab2 = new QWidget; 220 | textEdit = new QTextEdit; 221 | 222 | textEdit->setPlainText(tr("Twinkle, twinkle, little star,\n" 223 | "How I wonder what you are.\n" 224 | "Up above the world so high,\n" 225 | "Like a diamond in the sky.\n" 226 | "Twinkle, twinkle, little star,\n" 227 | "How I wonder what you are!\n")); 228 | 229 | QHBoxLayout *tab2hbox = new QHBoxLayout; 230 | tab2hbox->setMargin(5); 231 | tab2hbox->addWidget(textEdit); 232 | tab2->setLayout(tab2hbox); 233 | 234 | bottomLeftTabWidget->addTab(tab1, tr("&Table")); 235 | bottomLeftTabWidget->addTab(tab2, tr("Text &Edit")); 236 | } 237 | 238 | void WidgetGallery::createBottomRightGroupBox() 239 | { 240 | bottomRightGroupBox = new QGroupBox(tr("Group 3")); 241 | bottomRightGroupBox->setCheckable(true); 242 | bottomRightGroupBox->setChecked(true); 243 | 244 | lineEdit = new QLineEdit("s3cRe7"); 245 | lineEdit->setEchoMode(QLineEdit::Password); 246 | 247 | spinBox = new QSpinBox(bottomRightGroupBox); 248 | spinBox->setValue(50); 249 | 250 | dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox); 251 | dateTimeEdit->setDateTime(QDateTime::currentDateTime()); 252 | 253 | slider = new QSlider(Qt::Horizontal, bottomRightGroupBox); 254 | slider->setValue(40); 255 | 256 | scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox); 257 | scrollBar->setValue(60); 258 | 259 | dial = new QDial(bottomRightGroupBox); 260 | dial->setValue(30); 261 | dial->setNotchesVisible(true); 262 | 263 | QGridLayout *layout = new QGridLayout; 264 | layout->addWidget(lineEdit, 0, 0, 1, 2); 265 | layout->addWidget(spinBox, 1, 0, 1, 2); 266 | layout->addWidget(dateTimeEdit, 2, 0, 1, 2); 267 | layout->addWidget(slider, 3, 0); 268 | layout->addWidget(scrollBar, 4, 0); 269 | layout->addWidget(dial, 3, 1, 2, 1); 270 | layout->setRowStretch(5, 1); 271 | bottomRightGroupBox->setLayout(layout); 272 | } 273 | 274 | //! [13] 275 | void WidgetGallery::createProgressBar() 276 | { 277 | progressBar = new QProgressBar; 278 | progressBar->setRange(0, 10000); 279 | progressBar->setValue(0); 280 | 281 | QTimer *timer = new QTimer(this); 282 | connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar())); 283 | timer->start(1000); 284 | } 285 | //! [13] 286 | -------------------------------------------------------------------------------- /refrence/styles/widgetgallery.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGETGALLERY_H 2 | #define WIDGETGALLERY_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | class QCheckBox; 8 | class QComboBox; 9 | class QDateTimeEdit; 10 | class QDial; 11 | class QGroupBox; 12 | class QLabel; 13 | class QLineEdit; 14 | class QProgressBar; 15 | class QPushButton; 16 | class QRadioButton; 17 | class QScrollBar; 18 | class QSlider; 19 | class QSpinBox; 20 | class QTabWidget; 21 | class QTableWidget; 22 | class QTextEdit; 23 | QT_END_NAMESPACE 24 | 25 | //! [0] 26 | class WidgetGallery : public QDialog 27 | { 28 | Q_OBJECT 29 | 30 | public: 31 | WidgetGallery(QWidget *parent = 0); 32 | 33 | private slots: 34 | void changeStyle(const QString &styleName); 35 | void changePalette(); 36 | void advanceProgressBar(); 37 | 38 | private: 39 | void createTopLeftGroupBox(); 40 | void createTopRightGroupBox(); 41 | void createBottomLeftTabWidget(); 42 | void createBottomRightGroupBox(); 43 | void createProgressBar(); 44 | 45 | QPalette originalPalette; 46 | 47 | QLabel *styleLabel; 48 | QComboBox *styleComboBox; 49 | QCheckBox *useStylePaletteCheckBox; 50 | QCheckBox *disableWidgetsCheckBox; 51 | //! [0] 52 | 53 | QGroupBox *topLeftGroupBox; 54 | QRadioButton *radioButton1; 55 | QRadioButton *radioButton2; 56 | QRadioButton *radioButton3; 57 | QCheckBox *checkBox; 58 | 59 | QGroupBox *topRightGroupBox; 60 | QPushButton *defaultPushButton; 61 | QPushButton *togglePushButton; 62 | QPushButton *flatPushButton; 63 | 64 | QTabWidget *bottomLeftTabWidget; 65 | QTableWidget *tableWidget; 66 | QTextEdit *textEdit; 67 | 68 | QGroupBox *bottomRightGroupBox; 69 | QLineEdit *lineEdit; 70 | QSpinBox *spinBox; 71 | QDateTimeEdit *dateTimeEdit; 72 | QSlider *slider; 73 | QScrollBar *scrollBar; 74 | QDial *dial; 75 | 76 | QProgressBar *progressBar; 77 | //! [1] 78 | }; 79 | //! [1] 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/image-processing/CMainTabDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "CMainTabDialog.h" 2 | #include "global.h" 3 | #include "norwegianwoodstyle.h" 4 | #include 5 | #include 6 | 7 | CMainTabDialog::CMainTabDialog(QWidget *parent) : QDialog(parent) 8 | { 9 | initUI(); 10 | QFont font = this->font(); 11 | font.setPixelSize(FONT_SIZE); 12 | setFont(font); 13 | QApplication::setStyle(new NorwegianWoodStyle); 14 | } 15 | 16 | //private: 17 | void CMainTabDialog::initUI(){ 18 | m_pMainTabWidget = new QTabWidget(this); 19 | m_pFileWidget = new CFileTab(this); 20 | m_pTextWidget = new CTextTab(this); 21 | m_pCustomizeWidget = new CCustomizeTab(this); 22 | m_pOutputWidget = new COutputTab(this); 23 | 24 | m_pMainTabWidget->setFixedSize(g_sizeDLG); 25 | 26 | m_pMainTabWidget->addTab(m_pFileWidget, tr("File")); 27 | m_pMainTabWidget->addTab(m_pTextWidget, tr("Text")); 28 | m_pMainTabWidget->addTab(m_pCustomizeWidget, tr("Custom")); 29 | m_pMainTabWidget->addTab(m_pOutputWidget, tr("Output")); 30 | 31 | QVBoxLayout *mainLayout = new QVBoxLayout; 32 | mainLayout->addWidget(m_pMainTabWidget); 33 | setLayout(mainLayout); 34 | setWindowTitle(tr("Image Merge Dialog(Steve M.)")); 35 | } 36 | -------------------------------------------------------------------------------- /src/image-processing/CMainTabDialog.h: -------------------------------------------------------------------------------- 1 | #ifndef CMAINTABDIALOG_H 2 | #define CMAINTABDIALOG_H 3 | 4 | #include 5 | #include 6 | 7 | #include "UI/CCustomizeTab.h" 8 | #include "UI/CFileTab.h" 9 | #include "UI/COutputTab.h" 10 | #include "UI/CTextTab.h" 11 | 12 | class CMainTabDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit CMainTabDialog(QWidget *parent = nullptr); 17 | CFileTab* getFileWidget(){return m_pFileWidget;} 18 | CTextTab* getTextWidget(){return m_pTextWidget;} 19 | CCustomizeTab* getCustomWidget(){return m_pCustomizeWidget;} 20 | COutputTab* getOutputWidget(){return m_pOutputWidget;} 21 | 22 | private: 23 | void initUI(); 24 | 25 | private: 26 | QTabWidget *m_pMainTabWidget; 27 | CFileTab *m_pFileWidget; 28 | CTextTab *m_pTextWidget; 29 | CCustomizeTab *m_pCustomizeWidget; 30 | COutputTab *m_pOutputWidget; 31 | 32 | signals: 33 | 34 | public slots: 35 | }; 36 | 37 | #endif // CMAINTABDIALOG_H 38 | -------------------------------------------------------------------------------- /src/image-processing/UI/CCustomizeTab.cpp: -------------------------------------------------------------------------------- 1 | #include "CCustomizeTab.h" 2 | #include "../global.h" 3 | 4 | //class CColorImage 5 | //public: 6 | CColorImage::CColorImage(QColor color, QWidget *parent) : QWidget(parent) 7 | { 8 | m_color = color; 9 | } 10 | 11 | //protected: 12 | void CColorImage::paintEvent(QPaintEvent *event){ 13 | QPainter paint(this); 14 | paint.fillRect(rect(), m_color); 15 | QWidget::paintEvent(event); 16 | } 17 | 18 | //class CCustomizeTab 19 | //public 20 | CCustomizeTab::CCustomizeTab(QWidget *parent) : QWidget(parent) 21 | { 22 | initUI(); 23 | setupFontTree(); 24 | connect(m_pFontTypeList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), 25 | this, SLOT(showFont(QTreeWidgetItem*))); 26 | connect(m_pFontTypeList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), 27 | this, SLOT(updateStyles(QTreeWidgetItem*,int))); 28 | connect(m_pFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(onFontSizeChange(int))); 29 | connect(m_pOpacitySpin, SIGNAL(valueChanged(int)), this, SLOT(onOpacitySpinChange(int))); 30 | connect(m_pOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(onOpacitySliderChange(int))); 31 | connect(m_pFontColorBtn, SIGNAL(clicked(bool)), this, SLOT(onFontColorClicked())); 32 | connect(m_pBackColorBtn, SIGNAL(clicked(bool)), this, SLOT(onBackColorClicked())); 33 | } 34 | 35 | CUSTOM_INFO CCustomizeTab::getCustomInfo(){ 36 | CUSTOM_INFO info; 37 | info.m_colorFont = m_pFontColorLabel->getColor(); 38 | info.m_colorBack = m_pBackColorLabel->getColor(); 39 | info.m_nOpacity = m_pOpacitySlider->value(); 40 | m_font.setPointSize(m_pFontSizeSpin->value()); 41 | info.m_font = m_font; 42 | return info; 43 | } 44 | 45 | //private: 46 | void CCustomizeTab::initUI(){ 47 | QHBoxLayout *pMainLayout = new QHBoxLayout(this); 48 | 49 | QLabel *pFontTypeLabel = new QLabel(tr("Font Type")); 50 | m_pFontTypeList = new QTreeWidget(this); 51 | m_pFontTypeList->setFixedWidth(g_sizeDLG.width()/3); 52 | 53 | QLabel *pFontSizeLabel = new QLabel(tr("Font Size : ")); 54 | m_pFontSizeSpin = new QSpinBox(this); 55 | m_pFontSizeSpin->setMinimum(1); 56 | m_pFontSizeSpin->setMaximum(100); 57 | m_pFontSizeSpin->setValue(50); 58 | 59 | QLabel *pFontColorLabel = new QLabel(tr("Font Color : ")); 60 | m_pFontColorLabel = new CColorImage(Qt::black, this); 61 | m_pFontColorLabel->setFixedSize(g_sizeDLG.height()/25, g_sizeDLG.height()/25); 62 | m_pFontColorBtn = new QPushButton(tr("Pick Color")); 63 | m_pFontColorBtn->setDefault(true); 64 | 65 | QLabel *pBackColorLabel = new QLabel(tr("Background Color : ")); 66 | m_pBackColorLabel = new CColorImage(Qt::white, this); 67 | m_pBackColorLabel->setFixedSize(g_sizeDLG.height()/25, g_sizeDLG.height()/25); 68 | m_pBackColorBtn = new QPushButton(tr("Pick Color")); 69 | m_pBackColorBtn->setDefault(true); 70 | 71 | m_pOpacityLabel = new QLabel(STR_OPACITY); 72 | m_pOpacitySpin = new QSpinBox(this); 73 | m_pOpacitySpin->setMinimum(0); 74 | m_pOpacitySpin->setMaximum(100); 75 | m_pOpacitySpin->setValue(100); 76 | 77 | m_pOpacitySlider = new QSlider(Qt::Horizontal, this); 78 | m_pOpacitySlider->setMinimum(0); 79 | m_pOpacitySlider->setMaximum(100); 80 | m_pOpacitySlider->setValue(100); 81 | 82 | QLabel *pExplainLabel = new QLabel(tr("(Value of alpha property between 0 and 100)")); 83 | QFont font = this->font(); 84 | font.setPixelSize(FONT_SIZE * 0.7); 85 | pExplainLabel->setFont(font); 86 | 87 | QLabel *pPreviewLabel = new QLabel(tr("Preview Text")); 88 | m_pPreviewTextEdit = new QTextEdit(this); 89 | 90 | QVBoxLayout *pTypeLayout = new QVBoxLayout(this); 91 | pTypeLayout->addWidget(pFontTypeLabel); 92 | pTypeLayout->addWidget(m_pFontTypeList); 93 | 94 | QHBoxLayout *pSizeLayout = new QHBoxLayout(this); 95 | pSizeLayout->addWidget(pFontSizeLabel); 96 | pSizeLayout->addWidget(m_pFontSizeSpin); 97 | 98 | QHBoxLayout *pColorLayout = new QHBoxLayout(this); 99 | pColorLayout->addWidget(pFontColorLabel); 100 | pColorLayout->addWidget(m_pFontColorLabel); 101 | pColorLayout->addWidget(m_pFontColorBtn); 102 | 103 | QHBoxLayout *pBackLayout = new QHBoxLayout(this); 104 | pBackLayout->addWidget(pBackColorLabel); 105 | pBackLayout->addWidget(m_pBackColorLabel); 106 | pBackLayout->addWidget(m_pBackColorBtn); 107 | 108 | QHBoxLayout *pOpacityLayout = new QHBoxLayout(this); 109 | pOpacityLayout->addWidget(m_pOpacityLabel); 110 | pOpacityLayout->addWidget(m_pOpacitySpin); 111 | 112 | QVBoxLayout *pVTempLayout = new QVBoxLayout(this); 113 | pVTempLayout->addLayout(pSizeLayout); 114 | pVTempLayout->addLayout(pColorLayout); 115 | pVTempLayout->addLayout(pBackLayout); 116 | pVTempLayout->addLayout(pOpacityLayout); 117 | pVTempLayout->addWidget(m_pOpacitySlider); 118 | pVTempLayout->addWidget(pExplainLabel); 119 | 120 | QVBoxLayout *pPreviewLayout = new QVBoxLayout(this); 121 | pPreviewLayout->addWidget(pPreviewLabel); 122 | pPreviewLayout->addWidget(m_pPreviewTextEdit); 123 | pPreviewLayout->addLayout(pVTempLayout); 124 | 125 | pMainLayout->addLayout(pTypeLayout); 126 | pMainLayout->addLayout(pPreviewLayout); 127 | setLayout(pMainLayout); 128 | } 129 | 130 | void CCustomizeTab::setupFontTree() 131 | { 132 | QFontDatabase database; 133 | m_pFontTypeList->setColumnCount(1); 134 | m_pFontTypeList->setHeaderLabels(QStringList() << tr("Font")); 135 | 136 | foreach (QString family, database.families()) { 137 | const QStringList styles = database.styles(family); 138 | if (styles.isEmpty()) 139 | continue; 140 | 141 | QTreeWidgetItem *familyItem = new QTreeWidgetItem(m_pFontTypeList); 142 | familyItem->setText(0, family); 143 | familyItem->setCheckState(0, Qt::Unchecked); 144 | familyItem->setFlags(familyItem->flags() | Qt::ItemIsAutoTristate); 145 | 146 | foreach (QString style, styles) { 147 | QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); 148 | styleItem->setText(0, style); 149 | styleItem->setCheckState(0, Qt::Unchecked); 150 | styleItem->setData(0, Qt::UserRole, QVariant(database.weight(family, style))); 151 | styleItem->setData(0, Qt::UserRole + 1, QVariant(database.italic(family, style))); 152 | } 153 | } 154 | } 155 | 156 | //private slots: 157 | void CCustomizeTab::showFont(QTreeWidgetItem *item) 158 | { 159 | if (!item) 160 | return; 161 | 162 | QString family; 163 | QString style; 164 | int weight; 165 | bool italic; 166 | int nFontSize; 167 | 168 | if (item->parent()) { 169 | family = item->parent()->text(0); 170 | style = item->text(0); 171 | weight = item->data(0, Qt::UserRole).toInt(); 172 | italic = item->data(0, Qt::UserRole + 1).toBool(); 173 | } else { 174 | family = item->text(0); 175 | style = item->child(0)->text(0); 176 | weight = item->child(0)->data(0, Qt::UserRole).toInt(); 177 | italic = item->child(0)->data(0, Qt::UserRole + 1).toBool(); 178 | } 179 | 180 | nFontSize = m_pFontSizeSpin->value(); 181 | 182 | QString oldText = m_pPreviewTextEdit->toPlainText().trimmed(); 183 | bool modified = m_pPreviewTextEdit->document()->isModified(); 184 | m_pPreviewTextEdit->clear(); 185 | QFont font(family, nFontSize, weight, italic); 186 | font.setStyleName(style); 187 | m_pPreviewTextEdit->document()->setDefaultFont(font); 188 | 189 | QTextCursor cursor = m_pPreviewTextEdit->textCursor(); 190 | QTextBlockFormat blockFormat; 191 | blockFormat.setAlignment(Qt::AlignCenter); 192 | cursor.insertBlock(blockFormat); 193 | 194 | if (modified) 195 | cursor.insertText(QString(oldText)); 196 | else 197 | cursor.insertText(QString("%1 %2").arg(family).arg(style)); 198 | 199 | m_pPreviewTextEdit->document()->setModified(modified); 200 | m_font = font; 201 | } 202 | 203 | void CCustomizeTab::updateStyles(QTreeWidgetItem *item, int column) 204 | { 205 | if (!item || column != 0) 206 | return; 207 | } 208 | 209 | void CCustomizeTab::onFontSizeChange(int nFontSize){ 210 | QString oldText = m_pPreviewTextEdit->toPlainText().trimmed(); 211 | bool modified = m_pPreviewTextEdit->document()->isModified(); 212 | m_pPreviewTextEdit->clear(); 213 | QFont font = m_pPreviewTextEdit->document()->defaultFont(); 214 | 215 | font.setPointSize(nFontSize); 216 | m_pPreviewTextEdit->document()->setDefaultFont(font); 217 | 218 | QTextCursor cursor = m_pPreviewTextEdit->textCursor(); 219 | QTextBlockFormat blockFormat; 220 | blockFormat.setAlignment(Qt::AlignCenter); 221 | cursor.insertBlock(blockFormat); 222 | 223 | cursor.insertText(QString(oldText)); 224 | m_pPreviewTextEdit->document()->setModified(modified); 225 | m_font = font; 226 | } 227 | 228 | void CCustomizeTab::onFontColorClicked(){ 229 | QColor color = m_pFontColorLabel->getColor(); 230 | color = QColorDialog::getColor(color); 231 | m_pFontColorLabel->setColor(color); 232 | 233 | QString oldText = m_pPreviewTextEdit->toPlainText().trimmed(); 234 | bool modified = m_pPreviewTextEdit->document()->isModified(); 235 | m_pPreviewTextEdit->clear(); 236 | m_pPreviewTextEdit->setTextColor(color); 237 | 238 | QTextCursor cursor = m_pPreviewTextEdit->textCursor(); 239 | QTextBlockFormat blockFormat; 240 | blockFormat.setAlignment(Qt::AlignCenter); 241 | cursor.insertBlock(blockFormat); 242 | 243 | cursor.insertText(QString(oldText)); 244 | m_pPreviewTextEdit->document()->setModified(modified); 245 | } 246 | 247 | void CCustomizeTab::onBackColorClicked(){ 248 | QColor color = m_pBackColorLabel->getColor(); 249 | color = QColorDialog::getColor(color); 250 | m_pBackColorLabel->setColor(color); 251 | 252 | QString oldText = m_pPreviewTextEdit->toPlainText().trimmed(); 253 | bool modified = m_pPreviewTextEdit->document()->isModified(); 254 | m_pPreviewTextEdit->clear(); 255 | m_pPreviewTextEdit->setTextBackgroundColor(color); 256 | 257 | QTextCursor cursor = m_pPreviewTextEdit->textCursor(); 258 | QTextBlockFormat blockFormat; 259 | blockFormat.setAlignment(Qt::AlignCenter); 260 | cursor.insertBlock(blockFormat); 261 | 262 | cursor.insertText(QString(oldText)); 263 | m_pPreviewTextEdit->document()->setModified(modified); 264 | } 265 | 266 | void CCustomizeTab::onOpacitySpinChange(int nOpacity){ 267 | m_pOpacitySlider->setValue(nOpacity); 268 | } 269 | 270 | void CCustomizeTab::onOpacitySliderChange(int nOpacity){ 271 | m_pOpacitySpin->setValue(nOpacity); 272 | } 273 | 274 | //protected: 275 | void CCustomizeTab::showEvent(QShowEvent *event){ 276 | showFont(m_pFontTypeList->topLevelItem(0)); 277 | QWidget::showEvent(event); 278 | } 279 | -------------------------------------------------------------------------------- /src/image-processing/UI/CCustomizeTab.h: -------------------------------------------------------------------------------- 1 | #ifndef CCUSTOMIZETAB_H 2 | #define CCUSTOMIZETAB_H 3 | 4 | #include 5 | #include 6 | #include "../global.h" 7 | 8 | class CColorImage : public QWidget{ 9 | Q_OBJECT 10 | public: 11 | explicit CColorImage(QColor color = Qt::black, QWidget *parent = nullptr); 12 | void setColor(QColor color){m_color = color;} 13 | QColor getColor(){return m_color;} 14 | 15 | private: 16 | QColor m_color; 17 | 18 | protected: 19 | void paintEvent(QPaintEvent *event); 20 | }; 21 | 22 | class CCustomizeTab : public QWidget 23 | { 24 | Q_OBJECT 25 | public: 26 | explicit CCustomizeTab(QWidget *parent = nullptr); 27 | CUSTOM_INFO getCustomInfo(); 28 | 29 | private: 30 | void initUI(); 31 | void setupFontTree(); 32 | 33 | private: 34 | QTreeWidget *m_pFontTypeList; 35 | QSpinBox *m_pFontSizeSpin; 36 | CColorImage *m_pFontColorLabel; 37 | QPushButton *m_pFontColorBtn; 38 | CColorImage *m_pBackColorLabel; 39 | QPushButton *m_pBackColorBtn; 40 | QTextEdit *m_pPreviewTextEdit; 41 | QLabel *m_pOpacityLabel; 42 | QSpinBox *m_pOpacitySpin; 43 | QSlider *m_pOpacitySlider; 44 | QFont m_font; 45 | 46 | signals: 47 | 48 | private slots: 49 | void showFont(QTreeWidgetItem *item); 50 | void updateStyles(QTreeWidgetItem *item, int column); 51 | void onFontSizeChange(int); 52 | void onFontColorClicked(); 53 | void onBackColorClicked(); 54 | void onOpacitySpinChange(int); 55 | void onOpacitySliderChange(int); 56 | 57 | protected: 58 | void showEvent(QShowEvent *event); 59 | }; 60 | 61 | #endif // CCUSTOMIZETAB_H 62 | -------------------------------------------------------------------------------- /src/image-processing/UI/CFileTab.cpp: -------------------------------------------------------------------------------- 1 | #include "CFileTab.h" 2 | #include "../global.h" 3 | #include 4 | #include 5 | 6 | static void findRecursion(const QString &path, const QList &pattern, QStringList *result) 7 | { 8 | QDir currentDir(path); 9 | const QString prefix = path + QLatin1Char('\\'); 10 | foreach (const QString &match, currentDir.entryList(pattern, QDir::Files | QDir::NoSymLinks)) 11 | result->append(prefix + match); 12 | foreach (const QString &dir, currentDir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot)) 13 | findRecursion(prefix + dir, pattern, result); 14 | } 15 | 16 | //public 17 | CFileTab::CFileTab(QWidget *parent) : QWidget(parent) 18 | { 19 | initUI(); 20 | 21 | connect(m_pAddImageBtn, SIGNAL(clicked(bool)), this, SLOT(onAddImageClickded())); 22 | connect(m_pAddFolderBtn, SIGNAL(clicked(bool)), this, SLOT(onAddFolderClickded())); 23 | connect(m_pRemoveFileBtn, SIGNAL(clicked(bool)), this, SLOT(onRemoveFileClickded())); 24 | connect(m_pClearFileBtn, SIGNAL(clicked(bool)), this, SLOT(onClearFileClickded())); 25 | connect(m_pAddExtBtn, SIGNAL(clicked(bool)), this, SLOT(onAddExtClickded())); 26 | connect(m_pRemoveExtBtn, SIGNAL(clicked(bool)), this, SLOT(onRemoveExtClickded())); 27 | connect(m_pClearExtBtn, SIGNAL(clicked(bool)), this, SLOT(onClearExtClickded())); 28 | connect(m_pFileListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onFileSelectionChangeded())); 29 | } 30 | 31 | QList CFileTab::getImagePaths(){ 32 | QList list; 33 | for(int i=0; icount(); i++){ 34 | list.append(m_pFileListWidget->item(i)->text()); 35 | } 36 | return list; 37 | } 38 | 39 | //private: 40 | void CFileTab::initUI(){ 41 | QVBoxLayout *pMainLayout = new QVBoxLayout(this); 42 | 43 | QFont font = this->font(); 44 | font.setPixelSize(FONT_SIZE * 0.7); 45 | 46 | //File Image 47 | QGroupBox *pImageGroupBox = new QGroupBox(tr("File Imge")); 48 | m_pAddImageBtn = new QPushButton(tr("Add Images")); 49 | m_pAddImageBtn->setDefault(true); 50 | 51 | m_pAddFolderBtn = new QPushButton(tr("Add Folder")); 52 | m_pAddFolderBtn->setDefault(true); 53 | 54 | m_pRemoveFileBtn = new QPushButton(tr("Remove Selected")); 55 | m_pRemoveFileBtn->setDefault(true); 56 | 57 | m_pClearFileBtn = new QPushButton(tr("Clear All Files")); 58 | m_pClearFileBtn->setDefault(true); 59 | 60 | m_pImportLabel = new QLabel(STR_BASE_FILES); 61 | m_pSelectLabel = new QLabel(STR_FILE_SELECTED); 62 | m_pFileListWidget = new QListWidget(this); 63 | m_pFileListWidget->setSelectionMode(QAbstractItemView::MultiSelection); 64 | m_pFileListWidget->setFixedSize(g_sizeDLG.width() * 0.7, g_sizeDLG.height() * 0.5); 65 | m_pFileListWidget->setFont(font); 66 | 67 | QVBoxLayout *pBtnLayout = new QVBoxLayout(this); 68 | pBtnLayout->addWidget(m_pAddImageBtn); 69 | pBtnLayout->addWidget(m_pAddFolderBtn); 70 | pBtnLayout->addWidget(m_pRemoveFileBtn); 71 | pBtnLayout->addWidget(m_pClearFileBtn); 72 | 73 | QHBoxLayout *pLabelLayout = new QHBoxLayout(this); 74 | pLabelLayout->addWidget(m_pImportLabel); 75 | pLabelLayout->addWidget(m_pSelectLabel); 76 | 77 | QVBoxLayout *pListLayout = new QVBoxLayout(this); 78 | pListLayout->addLayout(pLabelLayout); 79 | pListLayout->addWidget(m_pFileListWidget); 80 | 81 | QHBoxLayout *pFileLayout = new QHBoxLayout(this); 82 | pFileLayout->addLayout(pBtnLayout); 83 | pFileLayout->addLayout(pListLayout); 84 | 85 | pImageGroupBox->setLayout(pFileLayout); 86 | 87 | //File extensions 88 | QGroupBox *pExGroupBox = new QGroupBox(tr("File Extensions")); 89 | 90 | m_pAddExtBtn = new QPushButton(tr("Add Extension")); 91 | m_pAddExtBtn->setDefault(true); 92 | 93 | m_pRemoveExtBtn = new QPushButton(tr("Remove Selected Extension")); 94 | m_pRemoveExtBtn->setDefault(true); 95 | 96 | m_pClearExtBtn = new QPushButton(tr("Remove All Extensions")); 97 | m_pClearExtBtn->setDefault(true); 98 | 99 | QLabel *pFileTypeLabel = new QLabel(STR_FILE_TYPE); 100 | m_pExtLineEdit = new QLineEdit(this); 101 | m_pExtListWidget = new QListWidget(this); 102 | m_pExtListWidget->setSelectionMode(QAbstractItemView::MultiSelection); 103 | m_pExtListWidget->setFixedWidth(g_sizeDLG.width()/5); 104 | pFileTypeLabel->setFixedWidth(g_sizeDLG.width()/5); 105 | m_pExtLineEdit->setFixedWidth(g_sizeDLG.width()/5); 106 | 107 | QStringList listExt; 108 | listExt << ".png" << ".jpeg" << ".jpg" << ".gif" << ".bmp"; 109 | m_pExtListWidget->addItems(listExt); 110 | 111 | QVBoxLayout *pExBtnLayout = new QVBoxLayout(this); 112 | pExBtnLayout->addWidget(m_pAddExtBtn); 113 | pExBtnLayout->addWidget(m_pRemoveExtBtn); 114 | pExBtnLayout->addWidget(m_pClearExtBtn); 115 | 116 | QVBoxLayout *pFileTypeLayout = new QVBoxLayout(this); 117 | pFileTypeLayout->addStretch(); 118 | pFileTypeLayout->addWidget(pFileTypeLabel); 119 | pFileTypeLayout->addSpacing(g_sizeDLG.height()/90); 120 | pFileTypeLayout->addWidget(m_pExtLineEdit); 121 | pFileTypeLayout->addStretch(); 122 | 123 | QHBoxLayout *pExMainLayout = new QHBoxLayout(this); 124 | pExMainLayout->addLayout(pExBtnLayout); 125 | pExMainLayout->addLayout(pFileTypeLayout); 126 | pExMainLayout->addWidget(m_pExtListWidget); 127 | 128 | pExGroupBox->setLayout(pExMainLayout); 129 | 130 | pMainLayout->addWidget(pImageGroupBox); 131 | pMainLayout->addWidget(pExGroupBox); 132 | setLayout(pMainLayout); 133 | } 134 | 135 | void CFileTab::showImportFileCount(){ 136 | 137 | } 138 | //private slots: 139 | void CFileTab::onAddImageClickded(){ 140 | QStringList files = QFileDialog::getOpenFileNames(this, 141 | "Select one or more files to open", 142 | "/home", 143 | "Images (*.png *.jpeg *.jpg *.gif *.bmp)"); 144 | m_pFileListWidget->addItems(files); 145 | showImportFileCount(); 146 | } 147 | 148 | void CFileTab::onAddFolderClickded(){ 149 | QStringList result; 150 | QStringList listType; 151 | for(int i=0; icount(); i++){ 152 | listType.append("*" + m_pExtListWidget->item(i)->text()); 153 | } 154 | 155 | QString directory = 156 | QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this, tr("Find Files"), QDir::currentPath())); 157 | 158 | if (!directory.isEmpty()) { 159 | findRecursion(directory, listType, &result); 160 | } 161 | 162 | m_pFileListWidget->addItems(result); 163 | showImportFileCount(); 164 | } 165 | 166 | void CFileTab::onRemoveFileClickded(){ 167 | qDeleteAll(m_pFileListWidget->selectedItems()); 168 | showImportFileCount(); 169 | } 170 | 171 | void CFileTab::onClearFileClickded(){ 172 | m_pFileListWidget->clear(); 173 | showImportFileCount(); 174 | } 175 | 176 | void CFileTab::onAddExtClickded(){ 177 | QString strType = m_pExtLineEdit->text(); 178 | 179 | if(strType.isEmpty()) 180 | return; 181 | 182 | if(strType.left(1).compare(".") != 0){ 183 | strType = "." + strType; 184 | } 185 | if(m_pExtListWidget->findItems(strType, Qt::MatchExactly).isEmpty()) 186 | m_pExtListWidget->addItem(strType); 187 | m_pExtLineEdit->clear(); 188 | } 189 | 190 | void CFileTab::onRemoveExtClickded(){ 191 | qDeleteAll(m_pExtListWidget->selectedItems()); 192 | } 193 | 194 | void CFileTab::onClearExtClickded(){ 195 | m_pExtListWidget->clear(); 196 | } 197 | 198 | void CFileTab::onFileSelectionChangeded(){ 199 | QList listSel = m_pFileListWidget->selectedItems(); 200 | m_pSelectLabel->setText(QString::number(listSel.size()) + STR_FILE_SELECTED); 201 | } 202 | -------------------------------------------------------------------------------- /src/image-processing/UI/CFileTab.h: -------------------------------------------------------------------------------- 1 | #ifndef CFILETAB_H 2 | #define CFILETAB_H 3 | 4 | #include 5 | #include 6 | 7 | class CFileTab : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit CFileTab(QWidget *parent = nullptr); 12 | QList getImagePaths(); 13 | 14 | private: 15 | void initUI(); 16 | void showImportFileCount(); 17 | 18 | private: 19 | QPushButton *m_pAddImageBtn; 20 | QPushButton *m_pAddFolderBtn; 21 | QPushButton *m_pRemoveFileBtn; 22 | QPushButton *m_pClearFileBtn; 23 | 24 | QListWidget *m_pFileListWidget; 25 | QLabel *m_pImportLabel; 26 | QLabel *m_pSelectLabel; 27 | 28 | QPushButton *m_pAddExtBtn; 29 | QPushButton *m_pRemoveExtBtn; 30 | QPushButton *m_pClearExtBtn; 31 | 32 | QListWidget *m_pExtListWidget; 33 | QLineEdit *m_pExtLineEdit; 34 | 35 | signals: 36 | 37 | private slots: 38 | void onAddImageClickded(); 39 | void onAddFolderClickded(); 40 | void onRemoveFileClickded(); 41 | void onClearFileClickded(); 42 | void onAddExtClickded(); 43 | void onRemoveExtClickded(); 44 | void onClearExtClickded(); 45 | void onFileSelectionChangeded(); 46 | }; 47 | 48 | #endif // CFILETAB_H 49 | -------------------------------------------------------------------------------- /src/image-processing/UI/CMergeThread.cpp: -------------------------------------------------------------------------------- 1 | #include "CMergeThread.h" 2 | #include "../CMainTabDialog.h" 3 | 4 | CMergeThread::CMergeThread(QObject *parent) : QThread(parent) 5 | { 6 | m_listFiles = g_pMainDlg->getFileWidget()->getImagePaths(); 7 | m_textInfo = g_pMainDlg->getTextWidget()->getTextInfo(); 8 | m_customInfo = g_pMainDlg->getCustomWidget()->getCustomInfo(); 9 | m_outputInfo = g_pMainDlg->getOutputWidget()->getOuputInfo(); 10 | } 11 | 12 | void CMergeThread::run() 13 | { 14 | QList listFiles; 15 | for(int i=0; i < m_outputInfo.m_nCount; i++){ 16 | emit(processing(i+1)); 17 | qsrand(QDateTime::currentMSecsSinceEpoch()); 18 | listFiles = getFiles(); 19 | if(listFiles.empty()) 20 | continue; 21 | 22 | getMergeImage(listFiles); 23 | } 24 | } 25 | 26 | //private: 27 | int CMergeThread::getRandNum(){ 28 | int nRand; 29 | nRand = rand() * QTime::currentTime().msec(); 30 | qDebug() << nRand; 31 | return nRand; 32 | } 33 | 34 | QList CMergeThread::getFiles(){ 35 | QList list; 36 | for(int i=0; i < g_ImageCount[m_outputInfo.m_nTemplate]; i++){ 37 | QString strPath; 38 | strPath = m_listFiles.at(getRandNum() % m_listFiles.count()); 39 | list.append(strPath); 40 | } 41 | 42 | return list; 43 | } 44 | 45 | void CMergeThread::getMergeImage(QList listFiles){ 46 | int nTemplate = m_outputInfo.m_nTemplate; 47 | 48 | switch (nTemplate) { 49 | case 0: 50 | template1(listFiles); 51 | break; 52 | case 1: 53 | template2(listFiles); 54 | break; 55 | 56 | case 2: 57 | template3(listFiles); 58 | break; 59 | case 3: 60 | template4(listFiles); 61 | break; 62 | case 4: 63 | template5(listFiles); 64 | break; 65 | case 5: 66 | template6(listFiles); 67 | break; 68 | default: 69 | break; 70 | } 71 | } 72 | 73 | QString CMergeThread::getOutputFilePath(){ 74 | QString strRet, strRandName; 75 | strRet = m_outputInfo.m_strOutputPath + "\\" + m_outputInfo.m_strKeyword; 76 | strRandName = QString::number(getRandNum()%100) + "-" + QString::number(getRandNum()%1000) + "-" + QString::number(getRandNum()%10000) + ".jpg"; 77 | strRet += strRandName; 78 | 79 | return strRet; 80 | } 81 | 82 | void CMergeThread::template1(QList listFiles){ 83 | QImage sourceImg(listFiles.at(0)); 84 | QImage txtImg; 85 | int nW, nH; 86 | nW = PANEL_SIZE + 2 * INTERVAL_SIZE; 87 | nH = PANEL_SIZE + 2 * INTERVAL_SIZE; 88 | 89 | if(m_textInfo.m_bIsArea){//insert area 90 | if(m_textInfo.m_nAreaPos == TOP || m_textInfo.m_nAreaPos == BOTTOM){ 91 | txtImg = getAreaImage(PANEL_SIZE); 92 | nH += txtImg.height(); 93 | } 94 | 95 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 96 | QPainter painter(&targetImg); 97 | painter.fillRect(targetImg.rect(), Qt::white); 98 | 99 | switch (m_textInfo.m_nAreaPos) { 100 | case TOP: 101 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, txtImg); 102 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE + txtImg.height(), sourceImg); 103 | break; 104 | case BOTTOM: 105 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg); 106 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE + sourceImg.height(), txtImg); 107 | break; 108 | default: 109 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg); 110 | break; 111 | } 112 | 113 | painter.end(); 114 | targetImg.save(getOutputFilePath()); 115 | } 116 | else{//overlay 117 | if(m_textInfo.m_nOverlayPos != NONE_OVERLAY){ 118 | txtImg = getOverlayImage(PANEL_SIZE * 0.7); 119 | } 120 | 121 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 122 | QPainter painter(&targetImg); 123 | painter.fillRect(targetImg.rect(), Qt::white); 124 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg); 125 | 126 | addTextOverlayImage(painter, targetImg, txtImg); 127 | 128 | painter.end(); 129 | targetImg.save(getOutputFilePath()); 130 | } 131 | } 132 | 133 | void CMergeThread::template2(QList listFiles){ 134 | QImage sourceImg[2]; 135 | QImage txtImg; 136 | int nW, nH; 137 | int nImageCount; 138 | 139 | nImageCount = g_ImageCount[m_outputInfo.m_nTemplate]; 140 | nW = PANEL_SIZE*2 + 3 * INTERVAL_SIZE; 141 | nH = PANEL_SIZE + 2 * INTERVAL_SIZE; 142 | 143 | for(int i=0; i < nImageCount; i++){ 144 | sourceImg[i] = QImage(listFiles.at(i)); 145 | } 146 | 147 | if(m_textInfo.m_bIsArea){//insert area 148 | if(m_textInfo.m_nAreaPos == TOP || m_textInfo.m_nAreaPos == BOTTOM){ 149 | txtImg = getAreaImage(PANEL_SIZE*2 + INTERVAL_SIZE); 150 | nH += txtImg.height(); 151 | } 152 | 153 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 154 | QPainter painter(&targetImg); 155 | painter.fillRect(targetImg.rect(), Qt::white); 156 | 157 | switch (m_textInfo.m_nAreaPos) { 158 | case TOP: 159 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, txtImg); 160 | for(int i=0; i < nImageCount; i++){ 161 | painter.drawImage(INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, INTERVAL_SIZE + txtImg.height(), sourceImg[i]); 162 | } 163 | break; 164 | case BOTTOM: 165 | for(int i=0; i < nImageCount; i++){ 166 | painter.drawImage(INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, INTERVAL_SIZE, sourceImg[i]); 167 | } 168 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE + PANEL_SIZE, txtImg); 169 | break; 170 | default: 171 | for(int i=0; i < nImageCount; i++){ 172 | painter.drawImage(INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, INTERVAL_SIZE, sourceImg[i]); 173 | } 174 | break; 175 | } 176 | 177 | painter.end(); 178 | targetImg.save(getOutputFilePath()); 179 | } 180 | else{//overlay 181 | if(m_textInfo.m_nOverlayPos != NONE_OVERLAY){ 182 | txtImg = getOverlayImage(PANEL_SIZE * 0.7); 183 | } 184 | 185 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 186 | QPainter painter(&targetImg); 187 | painter.fillRect(targetImg.rect(), Qt::white); 188 | 189 | for(int i=0; i < nImageCount; i++){ 190 | painter.drawImage(INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, INTERVAL_SIZE, sourceImg[i]); 191 | } 192 | 193 | addTextOverlayImage(painter, targetImg, txtImg); 194 | 195 | painter.end(); 196 | targetImg.save(getOutputFilePath()); 197 | } 198 | } 199 | 200 | void CMergeThread::template3(QList listFiles){ 201 | QImage sourceImg[2]; 202 | QImage txtImg; 203 | int nW, nH; 204 | int nImageCount; 205 | 206 | nImageCount = g_ImageCount[m_outputInfo.m_nTemplate]; 207 | nW = PANEL_SIZE + 2 * INTERVAL_SIZE; 208 | nH = PANEL_SIZE*2 + 3 * INTERVAL_SIZE; 209 | 210 | for(int i=0; i < nImageCount; i++){ 211 | sourceImg[i] = QImage(listFiles.at(i)); 212 | } 213 | 214 | if(m_textInfo.m_bIsArea){//insert area 215 | if(m_textInfo.m_nAreaPos != NONE_AREA){ 216 | txtImg = getAreaImage(PANEL_SIZE); 217 | nH += txtImg.height(); 218 | nH += INTERVAL_SIZE; 219 | } 220 | 221 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 222 | QPainter painter(&targetImg); 223 | painter.fillRect(targetImg.rect(), Qt::white); 224 | 225 | switch (m_textInfo.m_nAreaPos) { 226 | case TOP: 227 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, txtImg); 228 | for(int i=0; i < nImageCount; i++){ 229 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+2) + PANEL_SIZE*i + txtImg.height(), sourceImg[i]); 230 | } 231 | break; 232 | case MIDDLE: 233 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 234 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, txtImg); 235 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE + txtImg.height(), sourceImg[1]); 236 | break; 237 | case BOTTOM: 238 | for(int i=0; i < nImageCount; i++){ 239 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, sourceImg[i]); 240 | } 241 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE * (nImageCount+1) + PANEL_SIZE*2, txtImg); 242 | break; 243 | default: 244 | for(int i=0; i < nImageCount; i++){ 245 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, sourceImg[i]); 246 | } 247 | break; 248 | } 249 | 250 | painter.end(); 251 | targetImg.save(getOutputFilePath()); 252 | } 253 | else{//overlay 254 | if(m_textInfo.m_nOverlayPos != NONE_OVERLAY){ 255 | txtImg = getOverlayImage(PANEL_SIZE * 0.7); 256 | } 257 | 258 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 259 | QPainter painter(&targetImg); 260 | painter.fillRect(targetImg.rect(), Qt::white); 261 | 262 | for(int i=0; i < nImageCount; i++){ 263 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, sourceImg[i]); 264 | } 265 | 266 | addTextOverlayImage(painter, targetImg, txtImg); 267 | 268 | painter.end(); 269 | targetImg.save(getOutputFilePath()); 270 | } 271 | } 272 | 273 | void CMergeThread::template4(QList listFiles){ 274 | QImage sourceImg[4]; 275 | QImage txtImg; 276 | int nW, nH; 277 | int nImageCount; 278 | 279 | nImageCount = g_ImageCount[m_outputInfo.m_nTemplate]; 280 | nW = PANEL_SIZE*2 + 3 * INTERVAL_SIZE; 281 | nH = PANEL_SIZE*2 + 3 * INTERVAL_SIZE; 282 | 283 | for(int i=0; i < nImageCount; i++){ 284 | sourceImg[i] = QImage(listFiles.at(i)); 285 | } 286 | 287 | if(m_textInfo.m_bIsArea){//insert area 288 | if(m_textInfo.m_nAreaPos != NONE_AREA){ 289 | txtImg = getAreaImage(PANEL_SIZE*2 + INTERVAL_SIZE); 290 | nH += txtImg.height(); 291 | nH += INTERVAL_SIZE; 292 | } 293 | 294 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 295 | QPainter painter(&targetImg); 296 | painter.fillRect(targetImg.rect(), Qt::white); 297 | 298 | switch (m_textInfo.m_nAreaPos) { 299 | case TOP: 300 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, txtImg); 301 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + txtImg.height(), sourceImg[0]); 302 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + txtImg.height(), sourceImg[1]); 303 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE + txtImg.height(), sourceImg[2]); 304 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE + txtImg.height(), sourceImg[3]); 305 | break; 306 | case MIDDLE: 307 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 308 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE, sourceImg[1]); 309 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, txtImg); 310 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE + txtImg.height(), sourceImg[2]); 311 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE + txtImg.height(), sourceImg[3]); 312 | break; 313 | case BOTTOM: 314 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 315 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE, sourceImg[1]); 316 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[2]); 317 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[3]); 318 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE*2, txtImg); 319 | break; 320 | default: 321 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 322 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE, sourceImg[1]); 323 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[2]); 324 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[3]); 325 | break; 326 | } 327 | 328 | painter.end(); 329 | targetImg.save(getOutputFilePath()); 330 | } 331 | else{//overlay 332 | if(m_textInfo.m_nOverlayPos != NONE_OVERLAY){ 333 | txtImg = getOverlayImage(PANEL_SIZE * 0.7); 334 | } 335 | 336 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 337 | QPainter painter(&targetImg); 338 | painter.fillRect(targetImg.rect(), Qt::white); 339 | 340 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 341 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE, sourceImg[1]); 342 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[2]); 343 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[3]); 344 | 345 | addTextOverlayImage(painter, targetImg, txtImg); 346 | 347 | painter.end(); 348 | targetImg.save(getOutputFilePath()); 349 | } 350 | } 351 | 352 | void CMergeThread::template5(QList listFiles){ 353 | QImage sourceImg[3]; 354 | QImage txtImg; 355 | int nW, nH; 356 | int nImageCount; 357 | 358 | nImageCount = g_ImageCount[m_outputInfo.m_nTemplate]; 359 | nW = PANEL_SIZE + 2 * INTERVAL_SIZE; 360 | nH = PANEL_SIZE*3 + 4 * INTERVAL_SIZE; 361 | 362 | for(int i=0; i < nImageCount; i++){ 363 | sourceImg[i] = QImage(listFiles.at(i)); 364 | } 365 | 366 | if(m_textInfo.m_bIsArea){//insert area 367 | if(m_textInfo.m_nAreaPos == TOP || m_textInfo.m_nAreaPos == BOTTOM){ 368 | txtImg = getAreaImage(PANEL_SIZE); 369 | nH += txtImg.height(); 370 | nH += INTERVAL_SIZE; 371 | } 372 | 373 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 374 | QPainter painter(&targetImg); 375 | painter.fillRect(targetImg.rect(), Qt::white); 376 | 377 | switch (m_textInfo.m_nAreaPos) { 378 | case TOP: 379 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, txtImg); 380 | for(int i=0; i < nImageCount; i++){ 381 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+2) + PANEL_SIZE*i + txtImg.height(), sourceImg[i]); 382 | } 383 | break; 384 | case BOTTOM: 385 | for(int i=0; i < nImageCount; i++){ 386 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, sourceImg[i]); 387 | } 388 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE * (nImageCount+1) + PANEL_SIZE*2, txtImg); 389 | break; 390 | default: 391 | for(int i=0; i < nImageCount; i++){ 392 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, sourceImg[i]); 393 | } 394 | break; 395 | } 396 | 397 | painter.end(); 398 | targetImg.save(getOutputFilePath()); 399 | } 400 | else{//overlay 401 | if(m_textInfo.m_nOverlayPos != NONE_OVERLAY){ 402 | txtImg = getOverlayImage(PANEL_SIZE * 0.7); 403 | } 404 | 405 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 406 | QPainter painter(&targetImg); 407 | painter.fillRect(targetImg.rect(), Qt::white); 408 | 409 | for(int i=0; i < nImageCount; i++){ 410 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*(i+1) + PANEL_SIZE*i, sourceImg[i]); 411 | } 412 | 413 | addTextOverlayImage(painter, targetImg, txtImg); 414 | 415 | painter.end(); 416 | targetImg.save(getOutputFilePath()); 417 | } 418 | } 419 | 420 | void CMergeThread::template6(QList listFiles){ 421 | QImage sourceImg[5]; 422 | QImage txtImg; 423 | int nW, nH; 424 | int nImageCount; 425 | 426 | nImageCount = g_ImageCount[m_outputInfo.m_nTemplate]; 427 | nW = PANEL_SIZE*2 + 3 * INTERVAL_SIZE; 428 | nH = PANEL_SIZE*2 + 3 * INTERVAL_SIZE; 429 | 430 | for(int i=0; i < nImageCount; i++){ 431 | sourceImg[i] = QImage(listFiles.at(i)); 432 | } 433 | 434 | QImage popupImg((PANEL_SIZE + INTERVAL_SIZE*2), (PANEL_SIZE + INTERVAL_SIZE*2), QImage::Format_ARGB32_Premultiplied); 435 | QPainter painterPop(&popupImg); 436 | painterPop.fillRect(popupImg.rect(), Qt::white); 437 | painterPop.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, QImage(listFiles[nImageCount-1])); 438 | painterPop.end(); 439 | 440 | if(m_textInfo.m_bIsArea){//insert area 441 | if(m_textInfo.m_nAreaPos == TOP || m_textInfo.m_nAreaPos == BOTTOM){ 442 | txtImg = getAreaImage(PANEL_SIZE*2 + INTERVAL_SIZE); 443 | nH += txtImg.height(); 444 | nH += INTERVAL_SIZE; 445 | } 446 | 447 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 448 | QPainter painter(&targetImg); 449 | painter.fillRect(targetImg.rect(), Qt::white); 450 | 451 | switch (m_textInfo.m_nAreaPos) { 452 | case TOP: 453 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, txtImg); 454 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + txtImg.height(), sourceImg[0]); 455 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + txtImg.height(), sourceImg[1]); 456 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE + txtImg.height(), sourceImg[2]); 457 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE + txtImg.height(), sourceImg[3]); 458 | break; 459 | case BOTTOM: 460 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 461 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE, sourceImg[1]); 462 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[2]); 463 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[3]); 464 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*3 + PANEL_SIZE*2, txtImg); 465 | break; 466 | default: 467 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 468 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE, sourceImg[1]); 469 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[2]); 470 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[3]); 471 | break; 472 | } 473 | 474 | painter.drawImage((targetImg.width()-popupImg.width())/2, (targetImg.height()-popupImg.height())/2, popupImg); 475 | painter.end(); 476 | targetImg.save(getOutputFilePath()); 477 | } 478 | else{//overlay 479 | if(m_textInfo.m_nOverlayPos != NONE_OVERLAY){ 480 | txtImg = getOverlayImage(PANEL_SIZE * 0.7); 481 | } 482 | 483 | QImage targetImg(nW, nH, QImage::Format_ARGB32_Premultiplied); 484 | QPainter painter(&targetImg); 485 | painter.fillRect(targetImg.rect(), Qt::white); 486 | 487 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE, sourceImg[0]); 488 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE, sourceImg[1]); 489 | painter.drawImage(INTERVAL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[2]); 490 | painter.drawImage(INTERVAL_SIZE*2 + PANEL_SIZE, INTERVAL_SIZE*2 + PANEL_SIZE, sourceImg[3]); 491 | 492 | painter.drawImage((targetImg.width()-popupImg.width())/2, (targetImg.height()-popupImg.height())/2, popupImg); 493 | addTextOverlayImage(painter, targetImg, txtImg); 494 | 495 | painter.end(); 496 | targetImg.save(getOutputFilePath()); 497 | } 498 | } 499 | 500 | QImage CMergeThread::getAreaImage(int nW){ 501 | if(m_textInfo.m_listText.isEmpty() || (m_textInfo.m_bIsArea && m_textInfo.m_nAreaPos == NONE_AREA)){ 502 | //not input text in text tab. 503 | return QImage(); 504 | } 505 | 506 | int nTxtW, nTxtH, nLine; 507 | QFont font = m_customInfo.m_font; 508 | QFontMetrics mt(font); 509 | QString strText; 510 | int nRand; 511 | nRand = getRandNum() % m_textInfo.m_listText.count(); 512 | 513 | strText = m_textInfo.m_listText.at(nRand); 514 | nTxtW = mt.width(strText); 515 | nLine = nTxtW/nW; 516 | 517 | if(nTxtW % nW != 0) 518 | nLine++; 519 | nTxtH = nLine * mt.height(); 520 | 521 | QImage txtImg(nW, nTxtH, QImage::Format_ARGB32_Premultiplied); 522 | QPainter painterTxt(&txtImg); 523 | painterTxt.setFont(font); 524 | painterTxt.setPen(m_customInfo.m_colorFont); 525 | painterTxt.fillRect(txtImg.rect(), m_customInfo.m_colorBack); 526 | QTextOption options; 527 | options.setTextDirection(Qt::LayoutDirectionAuto); 528 | options.setWrapMode(QTextOption::WordWrap); 529 | options.setAlignment(Qt::AlignCenter); 530 | painterTxt.drawText(txtImg.rect(), strText, options); 531 | painterTxt.end(); 532 | 533 | return txtImg; 534 | } 535 | 536 | QImage CMergeThread::getOverlayImage(int nW){ 537 | if(m_textInfo.m_listText.isEmpty() || (!m_textInfo.m_bIsArea && m_textInfo.m_nOverlayPos == NONE_OVERLAY)){ 538 | //not input text in text tab. 539 | return QImage(); 540 | } 541 | 542 | int nTxtW, nTxtH, nLine; 543 | QFont font = m_customInfo.m_font; 544 | QFontMetrics mt(font); 545 | QString strText; 546 | int nRand; 547 | nRand = getRandNum() % m_textInfo.m_listText.count(); 548 | 549 | strText = m_textInfo.m_listText.at(nRand); 550 | nTxtW = mt.width(strText); 551 | nLine = nTxtW/nW; 552 | 553 | if(nTxtW % nW != 0) 554 | nLine++; 555 | nTxtH = nLine * mt.height(); 556 | 557 | QImage txtImg(nW, nTxtH, QImage::Format_ARGB32_Premultiplied); 558 | QPainter painterTxt(&txtImg); 559 | painterTxt.setFont(font); 560 | painterTxt.setPen(m_customInfo.m_colorFont); 561 | painterTxt.setOpacity(((qreal)m_customInfo.m_nOpacity)/(qreal)100.0); 562 | painterTxt.fillRect(txtImg.rect(), m_customInfo.m_colorBack); 563 | QTextOption options; 564 | options.setTextDirection(Qt::LayoutDirectionAuto); 565 | options.setWrapMode(QTextOption::WordWrap); 566 | options.setAlignment(Qt::AlignCenter); 567 | painterTxt.setOpacity(1); 568 | painterTxt.drawText(txtImg.rect(), strText, options); 569 | painterTxt.end(); 570 | 571 | return txtImg; 572 | } 573 | 574 | void CMergeThread::addTextOverlayImage(QPainter &painter, QImage &targetImg, QImage &txtImg){ 575 | switch (m_textInfo.m_nOverlayPos) { 576 | case TOP_LEFT: 577 | painter.drawImage(INTERVAL_SIZE*3, INTERVAL_SIZE*3, txtImg); 578 | break; 579 | case TOP_CENTER: 580 | painter.drawImage((targetImg.width() - txtImg.width())/2, INTERVAL_SIZE*3, txtImg); 581 | break; 582 | case TOP_RIGHT: 583 | painter.drawImage(targetImg.width() - txtImg.width() - INTERVAL_SIZE*3, INTERVAL_SIZE*3, txtImg); 584 | break; 585 | case MIDDLE_LEFT: 586 | painter.drawImage(INTERVAL_SIZE*3, (targetImg.height() - txtImg.height())/2, txtImg); 587 | break; 588 | case MIDDLE_CENTER: 589 | painter.drawImage((targetImg.width() - txtImg.width())/2, (targetImg.height() - txtImg.height())/2, txtImg); 590 | break; 591 | case MIDDLE_RIGHT: 592 | painter.drawImage(targetImg.width() - txtImg.width() - INTERVAL_SIZE*3, (targetImg.height() - txtImg.height())/2, txtImg); 593 | break; 594 | case BOTTOM_LEFT: 595 | painter.drawImage(INTERVAL_SIZE*3, targetImg.height() - txtImg.height() - INTERVAL_SIZE*3, txtImg); 596 | break; 597 | case BOTTOM_CENTER: 598 | painter.drawImage((targetImg.width() - txtImg.width())/2, targetImg.height() - txtImg.height() - INTERVAL_SIZE*3, txtImg); 599 | break; 600 | case BOTTOM_RIGHT: 601 | painter.drawImage(targetImg.width() - txtImg.width() - INTERVAL_SIZE*3, targetImg.height() - txtImg.height() - INTERVAL_SIZE*3, txtImg); 602 | break; 603 | default: 604 | break; 605 | } 606 | } 607 | -------------------------------------------------------------------------------- /src/image-processing/UI/CMergeThread.h: -------------------------------------------------------------------------------- 1 | #ifndef CMERGETHREAD_H 2 | #define CMERGETHREAD_H 3 | 4 | #include 5 | #include "../global.h" 6 | 7 | class CMergeThread : public QThread 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit CMergeThread(QObject *parent = nullptr); 12 | void run() override; 13 | 14 | private: 15 | int getRandNum(); 16 | QList getFiles(); 17 | void getMergeImage(QList listFiles); 18 | QString getOutputFilePath(); 19 | void template1(QList listFiles); 20 | void template2(QList listFiles); 21 | void template3(QList listFiles); 22 | void template4(QList listFiles); 23 | void template5(QList listFiles); 24 | void template6(QList listFiles); 25 | QImage getAreaImage(int nW); 26 | QImage getOverlayImage(int nW); 27 | void addTextOverlayImage(QPainter &painter, QImage &targetImg, QImage &txtImg); 28 | 29 | private: 30 | int m_nCount; 31 | QList m_listFiles; 32 | TEXT_INFO m_textInfo; 33 | CUSTOM_INFO m_customInfo; 34 | OUTPUT_INFO m_outputInfo; 35 | 36 | signals: 37 | void processing(int index); 38 | 39 | public slots: 40 | }; 41 | 42 | #endif // CMERGETHREAD_H 43 | -------------------------------------------------------------------------------- /src/image-processing/UI/COutputTab.cpp: -------------------------------------------------------------------------------- 1 | #include "COutputTab.h" 2 | #include "../global.h" 3 | #include "CMergeThread.h" 4 | 5 | COutputTab::COutputTab(QWidget *parent) : QWidget(parent) 6 | { 7 | initUI(); 8 | m_pTemplateRadio[0]->setChecked(true); 9 | connect(m_pOutputBtn, SIGNAL(clicked(bool)), this, SLOT(onOutputClicked())); 10 | connect(m_pStartMergeBtn, SIGNAL(clicked(bool)), this, SLOT(onMergeClicked())); 11 | } 12 | 13 | OUTPUT_INFO COutputTab::getOuputInfo(){ 14 | OUTPUT_INFO info; 15 | info.m_nCount = m_pImageNumSpin->value(); 16 | info.m_strKeyword = m_pKeywordEdit->text(); 17 | info.m_strOutputPath = m_pOutputEdit->text(); 18 | for(int i=0; iisChecked()){ 20 | info.m_nTemplate = i; 21 | break; 22 | } 23 | } 24 | 25 | return info; 26 | } 27 | 28 | //private: 29 | void COutputTab::initUI(){ 30 | QVBoxLayout *pMainLayout = new QVBoxLayout(this); 31 | 32 | m_pOutputBtn = new QPushButton(tr("Select Output Folder")); 33 | m_pOutputEdit = new QLineEdit(this); 34 | m_pOutputEdit->setFixedWidth(g_sizeDLG.width()*0.7); 35 | m_pOutputEdit->setPlaceholderText(tr("Select output path...")); 36 | m_pOutputEdit->setReadOnly(true); 37 | 38 | QLabel *pKeywordLabel = new QLabel(tr("Keyword : ")); 39 | m_pKeywordEdit = new QLineEdit(this); 40 | m_pKeywordEdit->setFixedWidth(g_sizeDLG.width()*0.7); 41 | m_pKeywordEdit->setPlaceholderText(tr("Input keyword...")); 42 | 43 | QLabel *pOutputLabel = new QLabel(tr("Output images : ")); 44 | m_pImageNumSpin = new QSpinBox(this); 45 | m_pImageNumSpin->setMinimum(1); 46 | m_pImageNumSpin->setMaximum(MAX_NUM); 47 | m_pImageNumSpin->setValue(1); 48 | 49 | m_pStartMergeBtn = new QPushButton(tr("Start Merging...")); 50 | 51 | m_pProgressBar = new QProgressBar(this); 52 | m_pProgressBar->setRange(0, 100); 53 | m_pProgressBar->setValue(0); 54 | 55 | QGroupBox *pTemplateGroupBox = new QGroupBox(tr("Merging Type")); 56 | m_pTemplateLabel = new QLabel(this); 57 | 58 | QPixmap img = QPixmap(":/images/template1.png"); 59 | m_pTemplateLabel->setPixmap(img); 60 | m_pTemplateLabel->setScaledContents(false); 61 | m_pTemplateLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 62 | 63 | QHBoxLayout *pPathLayout = new QHBoxLayout(this); 64 | pPathLayout->addWidget(m_pOutputBtn); 65 | pPathLayout->addWidget(m_pOutputEdit); 66 | 67 | QHBoxLayout *pKeywordLayout = new QHBoxLayout(this); 68 | pKeywordLayout->addWidget(pKeywordLabel); 69 | pKeywordLayout->addWidget(m_pKeywordEdit); 70 | 71 | QHBoxLayout *pNumLayout = new QHBoxLayout(this); 72 | pNumLayout->addWidget(pOutputLabel); 73 | pNumLayout->addWidget(m_pImageNumSpin); 74 | pNumLayout->addStretch(); 75 | 76 | QVBoxLayout *pRadioLayout = new QVBoxLayout(this); 77 | QFont font = this->font(); 78 | font.setPixelSize(FONT_SIZE * 0.7); 79 | for(int i=0; isetFixedWidth(g_sizeDLG.width()/5); 82 | m_pTemplateRadio[i]->setFont(font); 83 | pRadioLayout->addWidget(m_pTemplateRadio[i]); 84 | connect(m_pTemplateRadio[i], SIGNAL(clicked(bool)), this, SLOT(onTemplateClicked())); 85 | } 86 | 87 | QHBoxLayout *pTemplateLayout = new QHBoxLayout(this); 88 | pTemplateLayout->addLayout(pRadioLayout); 89 | pTemplateLayout->addWidget(m_pTemplateLabel, 0, Qt::AlignCenter); 90 | 91 | pTemplateGroupBox->setLayout(pTemplateLayout); 92 | 93 | pMainLayout->addLayout(pPathLayout); 94 | pMainLayout->addLayout(pKeywordLayout); 95 | pMainLayout->addLayout(pNumLayout); 96 | pMainLayout->addWidget(m_pStartMergeBtn); 97 | pMainLayout->addWidget(m_pProgressBar); 98 | pMainLayout->addWidget(pTemplateGroupBox); 99 | setLayout(pMainLayout); 100 | } 101 | 102 | //private slots: 103 | void COutputTab::onOutputClicked(){ 104 | QString directory = 105 | QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this, tr("Find Files"), QDir::currentPath())); 106 | 107 | if (!directory.isEmpty()) { 108 | m_pOutputEdit->setText(directory); 109 | } 110 | } 111 | 112 | void COutputTab::onMergeClicked(){ 113 | CMergeThread *pMergeThread = new CMergeThread(this); 114 | connect(pMergeThread, SIGNAL(processing(int)), this, SLOT(onProcessing(int))); 115 | connect(pMergeThread, SIGNAL(finished()), this, SLOT(onProcessingFinished())); 116 | connect(pMergeThread, SIGNAL(finished()), pMergeThread, SLOT(deleteLater())); 117 | pMergeThread->start(); 118 | m_pProgressBar->setValue(0); 119 | m_pStartMergeBtn->setEnabled(false); 120 | } 121 | 122 | void COutputTab::onTemplateClicked(){ 123 | QObject *object = QObject::sender(); 124 | QRadioButton* pbtn = qobject_cast(object); 125 | QString name = pbtn->text(); 126 | 127 | QPixmap img = QPixmap(":/images/" + name + ".png"); 128 | m_pTemplateLabel->setPixmap(img); 129 | } 130 | 131 | void COutputTab::onProcessing(int index){ 132 | int nVal; 133 | nVal = index * 100 / m_pImageNumSpin->value(); 134 | m_pProgressBar->setValue(nVal); 135 | } 136 | 137 | void COutputTab::onProcessingFinished(){ 138 | QMessageBox::information(this, "Info", "Process Successful."); 139 | m_pStartMergeBtn->setEnabled(true); 140 | m_pProgressBar->setValue(0); 141 | } 142 | -------------------------------------------------------------------------------- /src/image-processing/UI/COutputTab.h: -------------------------------------------------------------------------------- 1 | #ifndef COUTPUTTAB_H 2 | #define COUTPUTTAB_H 3 | 4 | #include 5 | #include 6 | #include "../global.h" 7 | 8 | class COutputTab : public QWidget 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit COutputTab(QWidget *parent = nullptr); 13 | OUTPUT_INFO getOuputInfo(); 14 | 15 | private: 16 | void initUI(); 17 | 18 | private: 19 | QPushButton *m_pOutputBtn; 20 | QLineEdit *m_pOutputEdit; 21 | QLineEdit *m_pKeywordEdit; 22 | QSpinBox *m_pImageNumSpin; 23 | QPushButton *m_pStartMergeBtn; 24 | QProgressBar *m_pProgressBar; 25 | QRadioButton *m_pTemplateRadio[TEMPLATE_NUM]; 26 | QLabel *m_pTemplateLabel; 27 | 28 | signals: 29 | 30 | private slots: 31 | void onOutputClicked(); 32 | void onMergeClicked(); 33 | void onTemplateClicked(); 34 | void onProcessing(int index); 35 | void onProcessingFinished(); 36 | }; 37 | 38 | #endif // COUTPUTTAB_H 39 | -------------------------------------------------------------------------------- /src/image-processing/UI/CTextTab.cpp: -------------------------------------------------------------------------------- 1 | #include "CTextTab.h" 2 | #include "../global.h" 3 | #include 4 | #include 5 | 6 | CTextTab::CTextTab(QWidget *parent) : QWidget(parent) 7 | { 8 | initUI(); 9 | m_pAreaRadioBtn->setChecked(true); 10 | connect(m_pAddTextBtn, SIGNAL(clicked(bool)), this, SLOT(onAddTextClicked())); 11 | connect(m_pRemoveBtn, SIGNAL(clicked(bool)), this, SLOT(onRemoveClicked())); 12 | connect(m_pClearBtn, SIGNAL(clicked(bool)), this, SLOT(onClearClicked())); 13 | connect(m_pAddCSVBtn, SIGNAL(clicked(bool)), this, SLOT(onAddCSVClicked())); 14 | connect(m_pAddTXTBtn, SIGNAL(clicked(bool)), this, SLOT(onAddTXTClicked())); 15 | } 16 | 17 | TEXT_INFO CTextTab::getTextInfo(){ 18 | TEXT_INFO info; 19 | info.m_bIsArea = m_pAreaRadioBtn->isChecked(); 20 | info.m_nAreaPos = (TEXT_AREA)m_pAreaCombo->currentIndex(); 21 | info.m_nOverlayPos = (TEXT_OVERLAY)m_pOverlayCombo->currentIndex(); 22 | for(int i=0; icount(); i++){ 23 | info.m_listText.append(m_pTextList->item(i)->text()); 24 | } 25 | return info; 26 | } 27 | 28 | //private: 29 | void CTextTab::initUI(){ 30 | QVBoxLayout *pMainLayout = new QVBoxLayout(this); 31 | 32 | //Select TextType and Area Position 33 | QGroupBox *pTypeGroupBox = new QGroupBox(tr("Text Type & Area Position")); 34 | 35 | m_pAreaRadioBtn = new QRadioButton(tr("Text Area")); 36 | QLabel *pAreaLabel = new QLabel(tr("Text Area Position : ")); 37 | m_pAreaCombo = new QComboBox(this); 38 | QStringList listArea; 39 | listArea << "None" << "Top" << "Middle"<< "Bottom"; 40 | m_pAreaCombo->addItems(listArea); 41 | 42 | m_pOverlayRadioBtn = new QRadioButton(tr("Text Overlay")); 43 | QLabel *pOverlayLabel = new QLabel(tr("Text Overlay Position : ")); 44 | m_pOverlayCombo = new QComboBox(this); 45 | QStringList listOverlay; 46 | listOverlay << "None" << "Top Left" << "Top Center" << "Top Right" << "Middle Left" << "Middle Center" << "Middle Right" << "Bottom Left" << "Bottom Center" << "Bottom Right"; 47 | m_pOverlayCombo->addItems(listOverlay); 48 | 49 | QHBoxLayout *pAreaLayout = new QHBoxLayout(this); 50 | pAreaLayout->addWidget(m_pAreaRadioBtn); 51 | pAreaLayout->addWidget(pAreaLabel); 52 | pAreaLayout->addWidget(m_pAreaCombo); 53 | //pAreaLayout->addStretch(); 54 | 55 | QHBoxLayout *pOverlayLayout = new QHBoxLayout(this); 56 | pOverlayLayout->addWidget(m_pOverlayRadioBtn); 57 | pOverlayLayout->addWidget(pOverlayLabel); 58 | pOverlayLayout->addWidget(m_pOverlayCombo); 59 | //pOverlayLayout->addStretch(); 60 | 61 | QVBoxLayout *pTypeLayout = new QVBoxLayout(this); 62 | pTypeLayout->addLayout(pAreaLayout); 63 | pTypeLayout->addLayout(pOverlayLayout); 64 | 65 | pTypeGroupBox->setLayout(pTypeLayout); 66 | 67 | //Spining Text 68 | QGroupBox *pSpinGroupBox = new QGroupBox(tr("Spinnig Text")); 69 | 70 | m_pSpinEdit = new QLineEdit(this); 71 | m_pSpinEdit->setPlaceholderText(tr("Input text here...")); 72 | 73 | m_pAddTextBtn = new QPushButton(tr("Add Text")); 74 | m_pAddTextBtn->setDefault(true); 75 | 76 | m_pRemoveBtn = new QPushButton(tr("Remove")); 77 | m_pRemoveBtn->setDefault(true); 78 | 79 | m_pClearBtn = new QPushButton(tr("Remove All")); 80 | m_pClearBtn->setDefault(true); 81 | 82 | m_pAddCSVBtn = new QPushButton(tr("Add via CSV File")); 83 | m_pAddCSVBtn->setDefault(true); 84 | 85 | m_pAddTXTBtn = new QPushButton(tr("Add via Text File")); 86 | m_pAddTXTBtn->setDefault(true); 87 | 88 | m_pTextList = new QListWidget(this); 89 | m_pTextList->setSelectionMode(QAbstractItemView::MultiSelection); 90 | 91 | QHBoxLayout *pBtnLayout = new QHBoxLayout(this); 92 | pBtnLayout->addWidget(m_pAddTextBtn); 93 | pBtnLayout->addWidget(m_pRemoveBtn); 94 | pBtnLayout->addWidget(m_pClearBtn); 95 | pBtnLayout->addWidget(m_pAddCSVBtn); 96 | pBtnLayout->addWidget(m_pAddTXTBtn); 97 | 98 | QVBoxLayout *pSpinLayout = new QVBoxLayout(this); 99 | pSpinLayout->addLayout(pBtnLayout); 100 | pSpinLayout->addWidget(m_pSpinEdit); 101 | pSpinLayout->addWidget(m_pTextList); 102 | 103 | pSpinGroupBox->setLayout(pSpinLayout); 104 | 105 | pMainLayout->addWidget(pTypeGroupBox); 106 | pMainLayout->addWidget(pSpinGroupBox); 107 | setLayout(pMainLayout); 108 | } 109 | 110 | //private slots: 111 | void CTextTab::onAddTextClicked(){ 112 | if(!m_pSpinEdit->text().isEmpty()) 113 | m_pTextList->addItem(m_pSpinEdit->text()); 114 | } 115 | 116 | void CTextTab::onRemoveClicked(){ 117 | qDeleteAll(m_pTextList->selectedItems()); 118 | } 119 | 120 | void CTextTab::onClearClicked(){ 121 | m_pTextList->clear(); 122 | } 123 | 124 | void CTextTab::onAddCSVClicked(){ 125 | QStringList files = QFileDialog::getOpenFileNames(this, 126 | "Select one or more files to open", 127 | "/home", 128 | "Excel Files (*.csv)"); 129 | for(int i=0; i lineItems = line.split(','); 140 | for(int i=0; iaddItems(wordList); 144 | } 145 | } 146 | 147 | void CTextTab::onAddTXTClicked(){ 148 | QStringList files = QFileDialog::getOpenFileNames(this, 149 | "Select one or more files to open", 150 | "/home", 151 | "Text Files (*.txt)"); 152 | for(int i=0; iaddItems(wordList); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/image-processing/UI/CTextTab.h: -------------------------------------------------------------------------------- 1 | #ifndef CTEXTTAB_H 2 | #define CTEXTTAB_H 3 | 4 | #include 5 | #include 6 | #include "../global.h" 7 | 8 | class CTextTab : public QWidget 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit CTextTab(QWidget *parent = nullptr); 13 | TEXT_INFO getTextInfo(); 14 | 15 | private: 16 | void initUI(); 17 | 18 | private: 19 | QRadioButton *m_pAreaRadioBtn; 20 | QRadioButton *m_pOverlayRadioBtn; 21 | QComboBox *m_pAreaCombo; 22 | QComboBox *m_pOverlayCombo; 23 | QLineEdit *m_pSpinEdit; 24 | QPushButton *m_pAddTextBtn; 25 | QPushButton *m_pRemoveBtn; 26 | QPushButton *m_pClearBtn; 27 | QPushButton *m_pAddCSVBtn; 28 | QPushButton *m_pAddTXTBtn; 29 | QListWidget *m_pTextList; 30 | signals: 31 | 32 | private slots: 33 | void onAddTextClicked(); 34 | void onRemoveClicked(); 35 | void onClearClicked(); 36 | void onAddCSVClicked(); 37 | void onAddTXTClicked(); 38 | }; 39 | 40 | #endif // CTEXTTAB_H 41 | -------------------------------------------------------------------------------- /src/image-processing/global.h: -------------------------------------------------------------------------------- 1 | #ifndef GLOBAL_H 2 | #define GLOBAL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class CMainTabDialog; 11 | extern CMainTabDialog *g_pMainDlg; 12 | 13 | enum TEXT_AREA{ 14 | NONE_AREA = 0, 15 | TOP, 16 | MIDDLE, 17 | BOTTOM 18 | }; 19 | 20 | enum TEXT_OVERLAY{ 21 | NONE_OVERLAY = 0, 22 | TOP_LEFT, 23 | TOP_CENTER, 24 | TOP_RIGHT, 25 | MIDDLE_LEFT, 26 | MIDDLE_CENTER, 27 | MIDDLE_RIGHT, 28 | BOTTOM_LEFT, 29 | BOTTOM_CENTER, 30 | BOTTOM_RIGHT 31 | }; 32 | 33 | struct TEXT_INFO{ 34 | bool m_bIsArea; 35 | TEXT_AREA m_nAreaPos; 36 | TEXT_OVERLAY m_nOverlayPos; 37 | QList m_listText; 38 | }; 39 | 40 | struct CUSTOM_INFO{ 41 | QFont m_font; 42 | QColor m_colorFont; 43 | QColor m_colorBack; 44 | int m_nOpacity; 45 | }; 46 | 47 | 48 | struct OUTPUT_INFO 49 | { 50 | QString m_strOutputPath; 51 | QString m_strKeyword; 52 | int m_nCount; 53 | int m_nTemplate; 54 | }; 55 | 56 | #define FONT_SIZE 20 57 | #define PANEL_SIZE 550 58 | #define INTERVAL_SIZE 10 59 | #define TEMPLATE_NUM 6 60 | #define MAX_NUM 300000 61 | 62 | const QSize g_sizeDLG(1024, 786); 63 | const QSize g_sizePhoto(2000, 1980); 64 | 65 | const QString STR_BASE_FILES(" base files"); 66 | const QString STR_FILE_SELECTED(" files selected"); 67 | const QString STR_FILE_TYPE("files type : "); 68 | const QString STR_OPACITY("Opacity : "); 69 | 70 | const int g_ImageCount[] = {1, 2, 2, 4, 3, 5}; 71 | #endif // GLOBAL_H 72 | -------------------------------------------------------------------------------- /src/image-processing/images/Untitled-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/Untitled-1.png -------------------------------------------------------------------------------- /src/image-processing/images/template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template.png -------------------------------------------------------------------------------- /src/image-processing/images/template1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template1.png -------------------------------------------------------------------------------- /src/image-processing/images/template2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template2.png -------------------------------------------------------------------------------- /src/image-processing/images/template3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template3.png -------------------------------------------------------------------------------- /src/image-processing/images/template4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template4.png -------------------------------------------------------------------------------- /src/image-processing/images/template5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template5.png -------------------------------------------------------------------------------- /src/image-processing/images/template6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template6.png -------------------------------------------------------------------------------- /src/image-processing/images/template7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template7.png -------------------------------------------------------------------------------- /src/image-processing/images/template8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/template8.png -------------------------------------------------------------------------------- /src/image-processing/images/woodbackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/woodbackground.png -------------------------------------------------------------------------------- /src/image-processing/images/woodbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeCooker19/Image-merge/3835ae58f3728d15bdff2c5fdf3f7df59d5a1474/src/image-processing/images/woodbutton.png -------------------------------------------------------------------------------- /src/image-processing/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "widgetgallery.h" 4 | #include "CMainTabDialog.h" 5 | 6 | CMainTabDialog *g_pMainDlg; 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | Q_INIT_RESOURCE(styles); 11 | 12 | QApplication app(argc, argv); 13 | 14 | QStringList paths = QCoreApplication::libraryPaths(); 15 | paths.append("."); 16 | paths.append("imageformats"); 17 | paths.append("platforms"); 18 | paths.append("sqldrivers"); 19 | QCoreApplication::setLibraryPaths(paths); 20 | 21 | CMainTabDialog tabDialog; 22 | g_pMainDlg = &tabDialog; 23 | tabDialog.show(); 24 | 25 | return app.exec(); 26 | } 27 | -------------------------------------------------------------------------------- /src/image-processing/norwegianwoodstyle.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include 52 | 53 | #include "norwegianwoodstyle.h" 54 | 55 | NorwegianWoodStyle::NorwegianWoodStyle() : 56 | QProxyStyle(QStyleFactory::create("windows")) 57 | { 58 | } 59 | 60 | //! [0] 61 | void NorwegianWoodStyle::polish(QPalette &palette) 62 | { 63 | QColor brown(212, 140, 95); 64 | QColor beige(236, 182, 120); 65 | QColor slightlyOpaqueBlack(0, 0, 0, 63); 66 | 67 | QPixmap backgroundImage(":/images/woodbackground.png"); 68 | QPixmap buttonImage(":/images/woodbutton.png"); 69 | QPixmap midImage = buttonImage; 70 | 71 | QPainter painter; 72 | painter.begin(&midImage); 73 | painter.setPen(Qt::NoPen); 74 | painter.fillRect(midImage.rect(), slightlyOpaqueBlack); 75 | painter.end(); 76 | //! [0] 77 | 78 | //! [1] 79 | palette = QPalette(brown); 80 | 81 | palette.setBrush(QPalette::BrightText, Qt::white); 82 | palette.setBrush(QPalette::Base, beige); 83 | palette.setBrush(QPalette::Highlight, Qt::darkGreen); 84 | setTexture(palette, QPalette::Button, buttonImage); 85 | setTexture(palette, QPalette::Mid, midImage); 86 | setTexture(palette, QPalette::Window, backgroundImage); 87 | 88 | QBrush brush = palette.background(); 89 | brush.setColor(brush.color().dark()); 90 | 91 | palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush); 92 | palette.setBrush(QPalette::Disabled, QPalette::Text, brush); 93 | palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush); 94 | palette.setBrush(QPalette::Disabled, QPalette::Base, brush); 95 | palette.setBrush(QPalette::Disabled, QPalette::Button, brush); 96 | palette.setBrush(QPalette::Disabled, QPalette::Mid, brush); 97 | } 98 | //! [1] 99 | 100 | //! [3] 101 | void NorwegianWoodStyle::polish(QWidget *widget) 102 | //! [3] //! [4] 103 | { 104 | if (qobject_cast(widget) 105 | || qobject_cast(widget)) 106 | widget->setAttribute(Qt::WA_Hover, true); 107 | } 108 | //! [4] 109 | 110 | //! [5] 111 | void NorwegianWoodStyle::unpolish(QWidget *widget) 112 | //! [5] //! [6] 113 | { 114 | if (qobject_cast(widget) 115 | || qobject_cast(widget)) 116 | widget->setAttribute(Qt::WA_Hover, false); 117 | } 118 | //! [6] 119 | 120 | //! [7] 121 | int NorwegianWoodStyle::pixelMetric(PixelMetric metric, 122 | //! [7] //! [8] 123 | const QStyleOption *option, 124 | const QWidget *widget) const 125 | { 126 | switch (metric) { 127 | case PM_ComboBoxFrameWidth: 128 | return 8; 129 | case PM_ScrollBarExtent: 130 | return QProxyStyle::pixelMetric(metric, option, widget) + 4; 131 | default: 132 | return QProxyStyle::pixelMetric(metric, option, widget); 133 | } 134 | } 135 | //! [8] 136 | 137 | //! [9] 138 | int NorwegianWoodStyle::styleHint(StyleHint hint, const QStyleOption *option, 139 | //! [9] //! [10] 140 | const QWidget *widget, 141 | QStyleHintReturn *returnData) const 142 | { 143 | switch (hint) { 144 | case SH_DitherDisabledText: 145 | return int(false); 146 | case SH_EtchDisabledText: 147 | return int(true); 148 | default: 149 | return QProxyStyle::styleHint(hint, option, widget, returnData); 150 | } 151 | } 152 | //! [10] 153 | 154 | //! [11] 155 | void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element, 156 | //! [11] //! [12] 157 | const QStyleOption *option, 158 | QPainter *painter, 159 | const QWidget *widget) const 160 | { 161 | switch (element) { 162 | case PE_PanelButtonCommand: 163 | { 164 | int delta = (option->state & State_MouseOver) ? 64 : 0; 165 | QColor slightlyOpaqueBlack(0, 0, 0, 63); 166 | QColor semiTransparentWhite(255, 255, 255, 127 + delta); 167 | QColor semiTransparentBlack(0, 0, 0, 127 - delta); 168 | 169 | int x, y, width, height; 170 | option->rect.getRect(&x, &y, &width, &height); 171 | //! [12] 172 | 173 | //! [13] 174 | QPainterPath roundRect = roundRectPath(option->rect); 175 | //! [13] //! [14] 176 | int radius = qMin(width, height) / 2; 177 | //! [14] 178 | 179 | //! [15] 180 | QBrush brush; 181 | //! [15] //! [16] 182 | bool darker; 183 | 184 | const QStyleOptionButton *buttonOption = 185 | qstyleoption_cast(option); 186 | if (buttonOption 187 | && (buttonOption->features & QStyleOptionButton::Flat)) { 188 | brush = option->palette.background(); 189 | darker = (option->state & (State_Sunken | State_On)); 190 | } else { 191 | if (option->state & (State_Sunken | State_On)) { 192 | brush = option->palette.mid(); 193 | darker = !(option->state & State_Sunken); 194 | } else { 195 | brush = option->palette.button(); 196 | darker = false; 197 | //! [16] //! [17] 198 | } 199 | //! [17] //! [18] 200 | } 201 | //! [18] 202 | 203 | //! [19] 204 | painter->save(); 205 | //! [19] //! [20] 206 | painter->setRenderHint(QPainter::Antialiasing, true); 207 | //! [20] //! [21] 208 | painter->fillPath(roundRect, brush); 209 | //! [21] //! [22] 210 | if (darker) 211 | //! [22] //! [23] 212 | painter->fillPath(roundRect, slightlyOpaqueBlack); 213 | //! [23] 214 | 215 | //! [24] 216 | int penWidth; 217 | //! [24] //! [25] 218 | if (radius < 10) 219 | penWidth = 3; 220 | else if (radius < 20) 221 | penWidth = 5; 222 | else 223 | penWidth = 7; 224 | 225 | QPen topPen(semiTransparentWhite, penWidth); 226 | QPen bottomPen(semiTransparentBlack, penWidth); 227 | 228 | if (option->state & (State_Sunken | State_On)) 229 | qSwap(topPen, bottomPen); 230 | //! [25] 231 | 232 | //! [26] 233 | int x1 = x; 234 | int x2 = x + radius; 235 | int x3 = x + width - radius; 236 | int x4 = x + width; 237 | 238 | if (option->direction == Qt::RightToLeft) { 239 | qSwap(x1, x4); 240 | qSwap(x2, x3); 241 | } 242 | 243 | QPolygon topHalf; 244 | topHalf << QPoint(x1, y) 245 | << QPoint(x4, y) 246 | << QPoint(x3, y + radius) 247 | << QPoint(x2, y + height - radius) 248 | << QPoint(x1, y + height); 249 | 250 | painter->setClipPath(roundRect); 251 | painter->setClipRegion(topHalf, Qt::IntersectClip); 252 | painter->setPen(topPen); 253 | painter->drawPath(roundRect); 254 | //! [26] //! [32] 255 | 256 | QPolygon bottomHalf = topHalf; 257 | bottomHalf[0] = QPoint(x4, y + height); 258 | 259 | painter->setClipPath(roundRect); 260 | painter->setClipRegion(bottomHalf, Qt::IntersectClip); 261 | painter->setPen(bottomPen); 262 | painter->drawPath(roundRect); 263 | 264 | painter->setPen(option->palette.foreground().color()); 265 | painter->setClipping(false); 266 | painter->drawPath(roundRect); 267 | 268 | painter->restore(); 269 | } 270 | break; 271 | //! [32] //! [33] 272 | default: 273 | //! [33] //! [34] 274 | QProxyStyle::drawPrimitive(element, option, painter, widget); 275 | } 276 | } 277 | //! [34] 278 | 279 | //! [35] 280 | void NorwegianWoodStyle::drawControl(ControlElement element, 281 | //! [35] //! [36] 282 | const QStyleOption *option, 283 | QPainter *painter, 284 | const QWidget *widget) const 285 | { 286 | switch (element) { 287 | case CE_PushButtonLabel: 288 | { 289 | QStyleOptionButton myButtonOption; 290 | const QStyleOptionButton *buttonOption = 291 | qstyleoption_cast(option); 292 | if (buttonOption) { 293 | myButtonOption = *buttonOption; 294 | if (myButtonOption.palette.currentColorGroup() 295 | != QPalette::Disabled) { 296 | if (myButtonOption.state & (State_Sunken | State_On)) { 297 | myButtonOption.palette.setBrush(QPalette::ButtonText, 298 | myButtonOption.palette.brightText()); 299 | } 300 | } 301 | } 302 | QProxyStyle::drawControl(element, &myButtonOption, painter, widget); 303 | } 304 | break; 305 | default: 306 | QProxyStyle::drawControl(element, option, painter, widget); 307 | } 308 | } 309 | //! [36] 310 | 311 | //! [37] 312 | void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role, 313 | //! [37] //! [38] 314 | const QPixmap &pixmap) 315 | { 316 | for (int i = 0; i < QPalette::NColorGroups; ++i) { 317 | QColor color = palette.brush(QPalette::ColorGroup(i), role).color(); 318 | palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap)); 319 | } 320 | } 321 | //! [38] 322 | 323 | //! [39] 324 | QPainterPath NorwegianWoodStyle::roundRectPath(const QRect &rect) 325 | //! [39] //! [40] 326 | { 327 | int radius = qMin(rect.width(), rect.height()) / 2; 328 | int diam = 2 * radius; 329 | 330 | int x1, y1, x2, y2; 331 | rect.getCoords(&x1, &y1, &x2, &y2); 332 | 333 | QPainterPath path; 334 | path.moveTo(x2, y1 + radius); 335 | path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0); 336 | path.lineTo(x1 + radius, y1); 337 | path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0); 338 | path.lineTo(x1, y2 - radius); 339 | path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0); 340 | path.lineTo(x1 + radius, y2); 341 | path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0); 342 | path.closeSubpath(); 343 | return path; 344 | } 345 | //! [40] 346 | -------------------------------------------------------------------------------- /src/image-processing/norwegianwoodstyle.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef NORWEGIANWOODSTYLE_H 52 | #define NORWEGIANWOODSTYLE_H 53 | 54 | #include 55 | #include 56 | 57 | QT_BEGIN_NAMESPACE 58 | class QPainterPath; 59 | QT_END_NAMESPACE 60 | 61 | //! [0] 62 | class NorwegianWoodStyle : public QProxyStyle 63 | { 64 | Q_OBJECT 65 | 66 | public: 67 | NorwegianWoodStyle(); 68 | 69 | void polish(QPalette &palette) override; 70 | void polish(QWidget *widget) override; 71 | void unpolish(QWidget *widget) override; 72 | int pixelMetric(PixelMetric metric, const QStyleOption *option, 73 | const QWidget *widget) const override; 74 | int styleHint(StyleHint hint, const QStyleOption *option, 75 | const QWidget *widget, QStyleHintReturn *returnData) const override; 76 | void drawPrimitive(PrimitiveElement element, const QStyleOption *option, 77 | QPainter *painter, const QWidget *widget) const override; 78 | void drawControl(ControlElement control, const QStyleOption *option, 79 | QPainter *painter, const QWidget *widget) const override; 80 | 81 | private: 82 | static void setTexture(QPalette &palette, QPalette::ColorRole role, 83 | const QPixmap &pixmap); 84 | static QPainterPath roundRectPath(const QRect &rect); 85 | }; 86 | //! [0] 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/image-processing/styles.pro: -------------------------------------------------------------------------------- 1 | QT += widgets core 2 | 3 | HEADERS = norwegianwoodstyle.h \ 4 | widgetgallery.h \ 5 | UI/CFileTab.h \ 6 | UI/CTextTab.h \ 7 | UI/COutputTab.h \ 8 | UI/CCustomizeTab.h \ 9 | CMainTabDialog.h \ 10 | global.h \ 11 | UI/CMergeThread.h 12 | SOURCES = main.cpp \ 13 | norwegianwoodstyle.cpp \ 14 | widgetgallery.cpp \ 15 | UI/CFileTab.cpp \ 16 | UI/CTextTab.cpp \ 17 | UI/COutputTab.cpp \ 18 | UI/CCustomizeTab.cpp \ 19 | CMainTabDialog.cpp \ 20 | UI/CMergeThread.cpp 21 | RESOURCES = styles.qrc 22 | 23 | # install 24 | target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/styles 25 | INSTALLS += target 26 | -------------------------------------------------------------------------------- /src/image-processing/styles.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/woodbutton.png 4 | images/woodbackground.png 5 | images/template.png 6 | images/template1.png 7 | images/template2.png 8 | images/template3.png 9 | images/template4.png 10 | images/template5.png 11 | images/template6.png 12 | images/template7.png 13 | images/template8.png 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/image-processing/widgetgallery.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include 52 | 53 | #include "norwegianwoodstyle.h" 54 | #include "widgetgallery.h" 55 | 56 | //! [0] 57 | WidgetGallery::WidgetGallery(QWidget *parent) 58 | : QDialog(parent) 59 | { 60 | originalPalette = QApplication::palette(); 61 | 62 | styleComboBox = new QComboBox; 63 | styleComboBox->addItem("NorwegianWood"); 64 | styleComboBox->addItems(QStyleFactory::keys()); 65 | 66 | styleLabel = new QLabel(tr("&Style:")); 67 | styleLabel->setBuddy(styleComboBox); 68 | 69 | useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette")); 70 | useStylePaletteCheckBox->setChecked(true); 71 | 72 | disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets")); 73 | 74 | createTopLeftGroupBox(); 75 | createTopRightGroupBox(); 76 | createBottomLeftTabWidget(); 77 | createBottomRightGroupBox(); 78 | createProgressBar(); 79 | //! [0] 80 | 81 | //! [1] 82 | connect(styleComboBox, SIGNAL(activated(QString)), 83 | //! [1] //! [2] 84 | this, SLOT(changeStyle(QString))); 85 | connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)), 86 | this, SLOT(changePalette())); 87 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 88 | topLeftGroupBox, SLOT(setDisabled(bool))); 89 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 90 | topRightGroupBox, SLOT(setDisabled(bool))); 91 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 92 | bottomLeftTabWidget, SLOT(setDisabled(bool))); 93 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), 94 | bottomRightGroupBox, SLOT(setDisabled(bool))); 95 | //! [2] 96 | 97 | //! [3] 98 | QHBoxLayout *topLayout = new QHBoxLayout; 99 | //! [3] //! [4] 100 | topLayout->addWidget(styleLabel); 101 | topLayout->addWidget(styleComboBox); 102 | topLayout->addStretch(1); 103 | topLayout->addWidget(useStylePaletteCheckBox); 104 | topLayout->addWidget(disableWidgetsCheckBox); 105 | 106 | QGridLayout *mainLayout = new QGridLayout; 107 | mainLayout->addLayout(topLayout, 0, 0, 1, 2); 108 | mainLayout->addWidget(topLeftGroupBox, 1, 0); 109 | mainLayout->addWidget(topRightGroupBox, 1, 1); 110 | mainLayout->addWidget(bottomLeftTabWidget, 2, 0); 111 | mainLayout->addWidget(bottomRightGroupBox, 2, 1); 112 | mainLayout->addWidget(progressBar, 3, 0, 1, 2); 113 | mainLayout->setRowStretch(1, 1); 114 | mainLayout->setRowStretch(2, 1); 115 | mainLayout->setColumnStretch(0, 1); 116 | mainLayout->setColumnStretch(1, 1); 117 | setLayout(mainLayout); 118 | 119 | setWindowTitle(tr("Styles")); 120 | changeStyle("NorwegianWood"); 121 | } 122 | //! [4] 123 | 124 | //! [5] 125 | void WidgetGallery::changeStyle(const QString &styleName) 126 | //! [5] //! [6] 127 | { 128 | if (styleName == "NorwegianWood") { 129 | //QApplication::setStyle(new NorwegianWoodStyle); 130 | } else { 131 | QApplication::setStyle(QStyleFactory::create(styleName)); 132 | } 133 | changePalette(); 134 | } 135 | //! [6] 136 | 137 | //! [7] 138 | void WidgetGallery::changePalette() 139 | //! [7] //! [8] 140 | { 141 | if (useStylePaletteCheckBox->isChecked()) 142 | QApplication::setPalette(QApplication::style()->standardPalette()); 143 | else 144 | QApplication::setPalette(originalPalette); 145 | } 146 | //! [8] 147 | 148 | //! [9] 149 | void WidgetGallery::advanceProgressBar() 150 | //! [9] //! [10] 151 | { 152 | int curVal = progressBar->value(); 153 | int maxVal = progressBar->maximum(); 154 | progressBar->setValue(curVal + (maxVal - curVal) / 100); 155 | } 156 | //! [10] 157 | 158 | //! [11] 159 | void WidgetGallery::createTopLeftGroupBox() 160 | //! [11] //! [12] 161 | { 162 | topLeftGroupBox = new QGroupBox(tr("Group 1")); 163 | 164 | radioButton1 = new QRadioButton(tr("Radio button 1")); 165 | radioButton2 = new QRadioButton(tr("Radio button 2")); 166 | radioButton3 = new QRadioButton(tr("Radio button 3")); 167 | radioButton1->setChecked(true); 168 | 169 | checkBox = new QCheckBox(tr("Tri-state check box")); 170 | checkBox->setTristate(true); 171 | checkBox->setCheckState(Qt::PartiallyChecked); 172 | 173 | QVBoxLayout *layout = new QVBoxLayout; 174 | layout->addWidget(radioButton1); 175 | layout->addWidget(radioButton2); 176 | layout->addWidget(radioButton3); 177 | layout->addWidget(checkBox); 178 | layout->addStretch(1); 179 | topLeftGroupBox->setLayout(layout); 180 | } 181 | //! [12] 182 | 183 | void WidgetGallery::createTopRightGroupBox() 184 | { 185 | topRightGroupBox = new QGroupBox(tr("Group 2")); 186 | 187 | defaultPushButton = new QPushButton(tr("Default Push Button")); 188 | defaultPushButton->setDefault(true); 189 | 190 | togglePushButton = new QPushButton(tr("Toggle Push Button")); 191 | togglePushButton->setCheckable(true); 192 | togglePushButton->setChecked(true); 193 | 194 | flatPushButton = new QPushButton(tr("Flat Push Button")); 195 | flatPushButton->setFlat(true); 196 | 197 | QVBoxLayout *layout = new QVBoxLayout; 198 | layout->addWidget(defaultPushButton); 199 | layout->addWidget(togglePushButton); 200 | layout->addWidget(flatPushButton); 201 | layout->addStretch(1); 202 | topRightGroupBox->setLayout(layout); 203 | } 204 | 205 | void WidgetGallery::createBottomLeftTabWidget() 206 | { 207 | bottomLeftTabWidget = new QTabWidget; 208 | bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred, 209 | QSizePolicy::Ignored); 210 | 211 | QWidget *tab1 = new QWidget; 212 | tableWidget = new QTableWidget(10, 10); 213 | 214 | QHBoxLayout *tab1hbox = new QHBoxLayout; 215 | tab1hbox->setMargin(5); 216 | tab1hbox->addWidget(tableWidget); 217 | tab1->setLayout(tab1hbox); 218 | 219 | QWidget *tab2 = new QWidget; 220 | textEdit = new QTextEdit; 221 | 222 | textEdit->setPlainText(tr("Twinkle, twinkle, little star,\n" 223 | "How I wonder what you are.\n" 224 | "Up above the world so high,\n" 225 | "Like a diamond in the sky.\n" 226 | "Twinkle, twinkle, little star,\n" 227 | "How I wonder what you are!\n")); 228 | 229 | QHBoxLayout *tab2hbox = new QHBoxLayout; 230 | tab2hbox->setMargin(5); 231 | tab2hbox->addWidget(textEdit); 232 | tab2->setLayout(tab2hbox); 233 | 234 | bottomLeftTabWidget->addTab(tab1, tr("&Table")); 235 | bottomLeftTabWidget->addTab(tab2, tr("Text &Edit")); 236 | } 237 | 238 | void WidgetGallery::createBottomRightGroupBox() 239 | { 240 | bottomRightGroupBox = new QGroupBox(tr("Group 3")); 241 | bottomRightGroupBox->setCheckable(true); 242 | bottomRightGroupBox->setChecked(true); 243 | 244 | lineEdit = new QLineEdit("s3cRe7"); 245 | lineEdit->setEchoMode(QLineEdit::Password); 246 | 247 | spinBox = new QSpinBox(bottomRightGroupBox); 248 | spinBox->setValue(50); 249 | 250 | dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox); 251 | dateTimeEdit->setDateTime(QDateTime::currentDateTime()); 252 | 253 | slider = new QSlider(Qt::Horizontal, bottomRightGroupBox); 254 | slider->setValue(40); 255 | 256 | scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox); 257 | scrollBar->setValue(60); 258 | 259 | dial = new QDial(bottomRightGroupBox); 260 | dial->setValue(30); 261 | dial->setNotchesVisible(true); 262 | 263 | QGridLayout *layout = new QGridLayout; 264 | layout->addWidget(lineEdit, 0, 0, 1, 2); 265 | layout->addWidget(spinBox, 1, 0, 1, 2); 266 | layout->addWidget(dateTimeEdit, 2, 0, 1, 2); 267 | layout->addWidget(slider, 3, 0); 268 | layout->addWidget(scrollBar, 4, 0); 269 | layout->addWidget(dial, 3, 1, 2, 1); 270 | layout->setRowStretch(5, 1); 271 | bottomRightGroupBox->setLayout(layout); 272 | } 273 | 274 | //! [13] 275 | void WidgetGallery::createProgressBar() 276 | { 277 | progressBar = new QProgressBar; 278 | progressBar->setRange(0, 10000); 279 | progressBar->setValue(0); 280 | 281 | QTimer *timer = new QTimer(this); 282 | connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar())); 283 | timer->start(1000); 284 | } 285 | //! [13] 286 | -------------------------------------------------------------------------------- /src/image-processing/widgetgallery.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGETGALLERY_H 2 | #define WIDGETGALLERY_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | class QCheckBox; 8 | class QComboBox; 9 | class QDateTimeEdit; 10 | class QDial; 11 | class QGroupBox; 12 | class QLabel; 13 | class QLineEdit; 14 | class QProgressBar; 15 | class QPushButton; 16 | class QRadioButton; 17 | class QScrollBar; 18 | class QSlider; 19 | class QSpinBox; 20 | class QTabWidget; 21 | class QTableWidget; 22 | class QTextEdit; 23 | QT_END_NAMESPACE 24 | 25 | //! [0] 26 | class WidgetGallery : public QDialog 27 | { 28 | Q_OBJECT 29 | 30 | public: 31 | WidgetGallery(QWidget *parent = 0); 32 | 33 | private slots: 34 | void changeStyle(const QString &styleName); 35 | void changePalette(); 36 | void advanceProgressBar(); 37 | 38 | private: 39 | void createTopLeftGroupBox(); 40 | void createTopRightGroupBox(); 41 | void createBottomLeftTabWidget(); 42 | void createBottomRightGroupBox(); 43 | void createProgressBar(); 44 | 45 | QPalette originalPalette; 46 | 47 | QLabel *styleLabel; 48 | QComboBox *styleComboBox; 49 | QCheckBox *useStylePaletteCheckBox; 50 | QCheckBox *disableWidgetsCheckBox; 51 | //! [0] 52 | 53 | QGroupBox *topLeftGroupBox; 54 | QRadioButton *radioButton1; 55 | QRadioButton *radioButton2; 56 | QRadioButton *radioButton3; 57 | QCheckBox *checkBox; 58 | 59 | QGroupBox *topRightGroupBox; 60 | QPushButton *defaultPushButton; 61 | QPushButton *togglePushButton; 62 | QPushButton *flatPushButton; 63 | 64 | QTabWidget *bottomLeftTabWidget; 65 | QTableWidget *tableWidget; 66 | QTextEdit *textEdit; 67 | 68 | QGroupBox *bottomRightGroupBox; 69 | QLineEdit *lineEdit; 70 | QSpinBox *spinBox; 71 | QDateTimeEdit *dateTimeEdit; 72 | QSlider *slider; 73 | QScrollBar *scrollBar; 74 | QDial *dial; 75 | 76 | QProgressBar *progressBar; 77 | //! [1] 78 | }; 79 | //! [1] 80 | 81 | #endif 82 | --------------------------------------------------------------------------------