Added line color change
This commit is contained in:
parent
baaf46a56f
commit
571094bc01
2
.gitignore
vendored
2
.gitignore
vendored
@ -55,3 +55,5 @@ compile_commands.json
|
|||||||
*creator.user*
|
*creator.user*
|
||||||
|
|
||||||
*_qmlcache.qrc
|
*_qmlcache.qrc
|
||||||
|
|
||||||
|
*.zip
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "ui_mywindow.h"
|
#include "ui_mywindow.h"
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QColorDialog>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include<float.h> // for float,double macros
|
#include<float.h> // for float,double macros
|
||||||
// Definicja konstruktora, wywolujemy najpierw
|
// Definicja konstruktora, wywolujemy najpierw
|
||||||
@ -58,6 +59,15 @@ void MyWindow::on_exitButton_clicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MyWindow::on_colorButton_clicked()
|
||||||
|
{
|
||||||
|
// qApp to globalny wskaznik do obiektu reprezentujacego aplikacje
|
||||||
|
// quit() to funkcja (slot) powodujaca zakonczenie aplikacji z kodem 0 (brak bledu)
|
||||||
|
color = QColorDialog::getColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Funkcja "odmalowujaca" komponent
|
// Funkcja "odmalowujaca" komponent
|
||||||
void MyWindow::paintEvent(QPaintEvent*)
|
void MyWindow::paintEvent(QPaintEvent*)
|
||||||
{
|
{
|
||||||
@ -114,6 +124,10 @@ void MyWindow::czysc()
|
|||||||
// Funkcja (slot) wywolywana po nacisnieciu przycisku myszy (w glownym oknie)
|
// Funkcja (slot) wywolywana po nacisnieciu przycisku myszy (w glownym oknie)
|
||||||
void MyWindow::mousePressEvent(QMouseEvent *event)
|
void MyWindow::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if(event->button() != Qt::LeftButton)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
UpdateTempImage();
|
UpdateTempImage();
|
||||||
|
|
||||||
// Pobieramy wspolrzedne punktu klikniecia
|
// Pobieramy wspolrzedne punktu klikniecia
|
||||||
@ -138,6 +152,7 @@ void MyWindow::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void MyWindow::mouseMoveEvent(QMouseEvent *event)
|
void MyWindow::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Pobieramy wspolrzedne punktu klikniecia
|
// Pobieramy wspolrzedne punktu klikniecia
|
||||||
int x = event->x();
|
int x = event->x();
|
||||||
int y = event->y();
|
int y = event->y();
|
||||||
@ -167,6 +182,9 @@ void MyWindow::mouseMoveEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::mouseReleaseEvent(QMouseEvent *event){
|
void MyWindow::mouseReleaseEvent(QMouseEvent *event){
|
||||||
|
if(event->button() != Qt::LeftButton)
|
||||||
|
return;
|
||||||
|
|
||||||
if(draw_finished)
|
if(draw_finished)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -208,7 +226,7 @@ void MyWindow::DrawLine(int x1, int y1, int x2, int y2){
|
|||||||
int x_form = x - x1;
|
int x_form = x - x1;
|
||||||
int y = a * x_form + y1;
|
int y = a * x_form + y1;
|
||||||
|
|
||||||
SetColor(ptr, QColor(255, 255, 255), x, y);
|
SetColor(ptr, color, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@ -222,15 +240,15 @@ void MyWindow::DrawLine(int x1, int y1, int x2, int y2){
|
|||||||
int y_form = y - y1;
|
int y_form = y - y1;
|
||||||
int x = ((float)(y_form) / a) + x1;
|
int x = ((float)(y_form) / a) + x1;
|
||||||
|
|
||||||
SetColor(ptr, QColor(255, 255, 255), x, y);
|
SetColor(ptr, color, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWindow::SetColor(unsigned char *ptr, QColor color, int x, int y){
|
void MyWindow::SetColor(unsigned char *ptr, QColor color, int x, int y){
|
||||||
ptr[szer*4*y + 4*x] = color.red();
|
ptr[szer*4*y + 4*x] = color.blue();
|
||||||
ptr[szer*4*y + 4*x + 1] = color.green();
|
ptr[szer*4*y + 4*x + 1] = color.green();
|
||||||
ptr[szer*4*y + 4*x + 2] = color.blue();
|
ptr[szer*4*y + 4*x + 2] = color.red();
|
||||||
ptr[szer*4*y + 4*x + 3] = 255;
|
ptr[szer*4*y + 4*x + 3] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ private:
|
|||||||
|
|
||||||
QImage *active_img;
|
QImage *active_img;
|
||||||
|
|
||||||
|
QColor color = QColor(255, 255, 255);
|
||||||
|
|
||||||
// Pola przechowujace szerokosc i wysokosc rysunku
|
// Pola przechowujace szerokosc i wysokosc rysunku
|
||||||
// oraz wspolrzedne jego lewego gornego naroznika
|
// oraz wspolrzedne jego lewego gornego naroznika
|
||||||
int szer;
|
int szer;
|
||||||
@ -92,6 +94,7 @@ private:
|
|||||||
private slots:
|
private slots:
|
||||||
void on_cleanButton_clicked();
|
void on_cleanButton_clicked();
|
||||||
void on_exitButton_clicked();
|
void on_exitButton_clicked();
|
||||||
|
void on_colorButton_clicked();
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
@ -51,9 +51,9 @@
|
|||||||
<widget class="QPushButton" name="cleanButton">
|
<widget class="QPushButton" name="cleanButton">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>80</x>
|
<x>60</x>
|
||||||
<y>40</y>
|
<y>50</y>
|
||||||
<width>75</width>
|
<width>125</width>
|
||||||
<height>23</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -64,9 +64,9 @@
|
|||||||
<widget class="QPushButton" name="exitButton">
|
<widget class="QPushButton" name="exitButton">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>80</x>
|
<x>60</x>
|
||||||
<y>70</y>
|
<y>80</y>
|
||||||
<width>75</width>
|
<width>125</width>
|
||||||
<height>23</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -74,6 +74,19 @@
|
|||||||
<string>Wyjście</string>
|
<string>Wyjście</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QPushButton" name="colorButton">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>60</x>
|
||||||
|
<y>110</y>
|
||||||
|
<width>125</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Wybierz kolor</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menuBar">
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
Loading…
Reference in New Issue
Block a user