Skip to content

Commit 71d4b66

Browse files
committed
fix resize image
1 parent fb8132c commit 71d4b66

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

client/mainwindow.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,17 @@ void MainWindow::fill_db_patterns(tinyxml2::XMLElement *body)
461461
QString img_64 {pattern->FirstChildElement("img")->GetText()};
462462
QString img_type {pattern->FirstChildElement("img_type")->GetText()};
463463

464-
QString path_to_image {QDir::currentPath() + "/images/" + name + "." + img_type};
464+
465+
QSqlQuery id_query("SELECT id FROM Pattern ORDER BY id DESC");
466+
id_query.next();
467+
QString id{QString::number(id_query.value(0).toInt() + 1)};
468+
469+
QString path_to_image {QDir::currentPath() + "/images/" + id + "." + img_type};
465470
this->save_img_to_file(path_to_image, img_64);
466471

467472
QSqlQuery insert("INSERT INTO Pattern (name, description, code, path_to_image)"
468473
" VALUES ('" + name + "', '" + description + "', '" + code + "', '" + path_to_image + "')");
469474

470-
471-
472-
473475
pattern = pattern->NextSiblingElement("pattern");
474476
}
475477
}
@@ -632,6 +634,19 @@ void MainWindow::on_more_btn_clicked(QString name)
632634

633635
this->pattern_pic = QPixmap();
634636
this->pattern_pic.load(data.path_to_image);
637+
int width{this->pattern_pic.width()};
638+
if (width > 512)
639+
{
640+
double ratio {width / 512.0};
641+
642+
this->pattern_pic = this->pattern_pic.scaled(512, int(this->pattern_pic.height() / ratio), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
643+
}
644+
else
645+
{
646+
double ratio {512.0 / width};
647+
648+
this->pattern_pic = this->pattern_pic.scaled(512, int(this->pattern_pic.height() * ratio), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
649+
}
635650

636651
this->ui->img_more->setPixmap(this->pattern_pic);
637652
}

client/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ private slots:
123123
/*для результатов тестов*/
124124
std::vector<QLabel*> label_test;
125125
std::vector<QFrame*> lines_test;
126+
126127
/*для списка паттернов*/
127128
std::vector<QLabel*> pattern_label_list;
128129
std::vector<QFrame*> pattern_frame_list;

client/mainwindow.ui

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>490</width>
10-
<height>369</height>
9+
<width>710</width>
10+
<height>539</height>
1111
</rect>
1212
</property>
13+
<property name="minimumSize">
14+
<size>
15+
<width>512</width>
16+
<height>0</height>
17+
</size>
18+
</property>
1319
<property name="windowTitle">
1420
<string>Паттерны Проектирования</string>
1521
</property>
@@ -22,7 +28,7 @@
2228
<item>
2329
<widget class="QStackedWidget" name="screen_stacked">
2430
<property name="currentIndex">
25-
<number>5</number>
31+
<number>3</number>
2632
</property>
2733
<widget class="QWidget" name="login">
2834
<layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -453,8 +459,8 @@
453459
<rect>
454460
<x>0</x>
455461
<y>0</y>
456-
<width>240</width>
457-
<height>20</height>
462+
<width>254</width>
463+
<height>460</height>
458464
</rect>
459465
</property>
460466
<layout class="QVBoxLayout" name="verticalLayout_4">
@@ -568,7 +574,7 @@
568574
<rect>
569575
<x>0</x>
570576
<y>0</y>
571-
<width>240</width>
577+
<width>237</width>
572578
<height>395</height>
573579
</rect>
574580
</property>
@@ -679,6 +685,12 @@
679685
</layout>
680686
</widget>
681687
<widget class="QWidget" name="more_pattern">
688+
<property name="minimumSize">
689+
<size>
690+
<width>512</width>
691+
<height>0</height>
692+
</size>
693+
</property>
682694
<layout class="QVBoxLayout" name="verticalLayout_2">
683695
<item>
684696
<widget class="QScrollArea" name="scrollArea_2">
@@ -689,11 +701,17 @@
689701
<property name="geometry">
690702
<rect>
691703
<x>0</x>
692-
<y>-310</y>
693-
<width>438</width>
694-
<height>599</height>
704+
<y>0</y>
705+
<width>655</width>
706+
<height>594</height>
695707
</rect>
696708
</property>
709+
<property name="minimumSize">
710+
<size>
711+
<width>512</width>
712+
<height>0</height>
713+
</size>
714+
</property>
697715
<layout class="QVBoxLayout" name="verticalLayout_5">
698716
<item>
699717
<widget class="QLabel" name="name_more">
@@ -763,21 +781,12 @@
763781
</item>
764782
<item>
765783
<widget class="QLabel" name="img_more">
766-
<property name="maximumSize">
767-
<size>
768-
<width>512</width>
769-
<height>512</height>
770-
</size>
771-
</property>
772784
<property name="text">
773785
<string/>
774786
</property>
775787
<property name="pixmap">
776788
<pixmap resource="res.qrc">:/default.png</pixmap>
777789
</property>
778-
<property name="scaledContents">
779-
<bool>false</bool>
780-
</property>
781790
<property name="alignment">
782791
<set>Qt::AlignCenter</set>
783792
</property>
@@ -822,7 +831,7 @@
822831
<rect>
823832
<x>0</x>
824833
<y>0</y>
825-
<width>490</width>
834+
<width>710</width>
826835
<height>21</height>
827836
</rect>
828837
</property>

0 commit comments

Comments
 (0)