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*
|
||||
|
||||
*_qmlcache.qrc
|
||||
|
||||
*.zip
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "ui_mywindow.h"
|
||||
#include <QColor>
|
||||
#include <QDebug>
|
||||
#include <QColorDialog>
|
||||
#include <iostream>
|
||||
#include<float.h> // for float,double macros
|
||||
// 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
|
||||
void MyWindow::paintEvent(QPaintEvent*)
|
||||
{
|
||||
@ -114,6 +124,10 @@ void MyWindow::czysc()
|
||||
// Funkcja (slot) wywolywana po nacisnieciu przycisku myszy (w glownym oknie)
|
||||
void MyWindow::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
|
||||
UpdateTempImage();
|
||||
|
||||
// Pobieramy wspolrzedne punktu klikniecia
|
||||
@ -138,6 +152,7 @@ void MyWindow::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void MyWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
|
||||
// Pobieramy wspolrzedne punktu klikniecia
|
||||
int x = event->x();
|
||||
int y = event->y();
|
||||
@ -167,6 +182,9 @@ void MyWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
|
||||
void MyWindow::mouseReleaseEvent(QMouseEvent *event){
|
||||
if(event->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if(draw_finished)
|
||||
return;
|
||||
|
||||
@ -208,7 +226,7 @@ void MyWindow::DrawLine(int x1, int y1, int x2, int y2){
|
||||
int x_form = x - x1;
|
||||
int y = a * x_form + y1;
|
||||
|
||||
SetColor(ptr, QColor(255, 255, 255), x, y);
|
||||
SetColor(ptr, color, x, y);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@ -222,15 +240,15 @@ void MyWindow::DrawLine(int x1, int y1, int x2, int y2){
|
||||
int y_form = y - y1;
|
||||
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){
|
||||
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 + 2] = color.blue();
|
||||
ptr[szer*4*y + 4*x + 2] = color.red();
|
||||
ptr[szer*4*y + 4*x + 3] = 255;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,8 @@ private:
|
||||
|
||||
QImage *active_img;
|
||||
|
||||
QColor color = QColor(255, 255, 255);
|
||||
|
||||
// Pola przechowujace szerokosc i wysokosc rysunku
|
||||
// oraz wspolrzedne jego lewego gornego naroznika
|
||||
int szer;
|
||||
@ -92,6 +94,7 @@ private:
|
||||
private slots:
|
||||
void on_cleanButton_clicked();
|
||||
void on_exitButton_clicked();
|
||||
void on_colorButton_clicked();
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
@ -51,9 +51,9 @@
|
||||
<widget class="QPushButton" name="cleanButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>40</y>
|
||||
<width>75</width>
|
||||
<x>60</x>
|
||||
<y>50</y>
|
||||
<width>125</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -64,9 +64,9 @@
|
||||
<widget class="QPushButton" name="exitButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>70</y>
|
||||
<width>75</width>
|
||||
<x>60</x>
|
||||
<y>80</y>
|
||||
<width>125</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -74,6 +74,19 @@
|
||||
<string>Wyjście</string>
|
||||
</property>
|
||||
</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 class="QMenuBar" name="menuBar">
|
||||
|
Loading…
Reference in New Issue
Block a user