-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gallery.cpp
156 lines (136 loc) · 5.05 KB
/
Gallery.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include<iostream>
#include "Gallery.h"
using namespace std;
void Gallery::insert(Image* im) // inserts image at the beginning of linked list
{
if (head == NULL) // check if list is empty
{
im->next = im; //make prev as well as next ptr point on the same image
im->prev = im;
head = im; // make head point on this new image
count++; // increments the count of images present in list
}
// if some images are already present in list, insert the new image at the beginning.
else
{
im->next = head;
im->prev = head->prev;
head->prev->next = im;
head->prev = im;
head = im; // make head point on the new image.
count++; // increments the count of images present in list
}
}
int Gallery::open_gallery()
{
if (head == NULL) // check if list is empty
{
cout << "\n\t\t\t\t\t\t\t\t\tYour Gallery is empty. No images found!" << endl;
return 0;
}
if (current == NULL) // check if any image is selelcted
current = head; // selects the first image
current->display(); // display the selected image
return 1;
}
void Gallery::copy_img()
{
// create a new Image object having the same attributes as the currently selected image.
Image* copy = new Image(current->r, current->c, (current->name + "(copy)"), current->date, current->size);
copy->accept(current->mat);
// insert this image copy in the list, after the selected image
copy->prev = current;
copy->next = current->next;
current->next->prev = copy;
current->next = copy;
clear_screen();
cout << "\n\t\t\t\t\t\t\t\t\tImage copy created successfully!" << endl;
current = current->next; // select the next image i.e. the copy
current->display(); // display the copy of image
}
void Gallery::delete_img()
{
if (head == NULL) // check if list is empty
{
cout << "\n\t\t\t\t\t\t\t\t\tYour Gallery is empty. No images found!" << endl;
}
else
{
Image* temp; // create a temp pointer which points to an Image object
if (current == head) // delete the head node
{
current->prev->next = current->next;
current->next->prev = current->prev;
temp = head;
current = current->next;
head = head->next;
count--;
delete temp;
clear_screen();
cout << "\n\t\t\t\t\t\t\t\t\t\t Image deleted!\n";
current->display(); // display the next image in Gallery
}
else // delete a node other than head node
{
current->next->prev = current->prev;
current->prev->next = current->next;
temp = current;
if (current == head) // first node is deleted
head = head->next;
current = current->next;
clear_screen();
cout << "\n\t\t\t\t\t\t\t\t\t\t Image deleted!\n";
count--;
if (count > 0)
current->display();
delete temp;
}
}
}
void Gallery::view_next() // moves pointer to next image and displays it
{
current = current->next;
clear_screen();
current->display();
}
void Gallery::view_prev() // moves pointer to previous image and displays it
{
current = current->prev;
clear_screen();
current->display();
}
void Gallery::edit()
{
int edit_choice; // stores the option selected by user
do {
cout << "\n\t\t\t\t\t\t\t\t\t\t\t*** Edit Menu ***" << endl;
cout << "\t\t\t\t\t\t\t\t1.Rotate Left\t\t2.Rotate Right\t\t3.Flip (Mirror Image)\n\t\t\t\t\t\t\t\t4.Crop\t\t\t5.Rename\t\t6.Back to Gallery\n\t\t\t\t\t\t\t\t>>";
cin >> edit_choice;
switch (edit_choice)
{
case 1: current->rotate_left(); break;
case 2: current->rotate_right(); break;
case 3: current->flip(); break;
case 4: current->crop(); break;
case 5: current->rename_img(); break;
case 6: clear_screen(); current->display(); break;
default: cout << "\t\t\t\t\t\t\t\tInvalid choice!" << endl;
}
} while (edit_choice != 6); // repeat the loop until the user selects option 6 i.e. return back
}
void Gallery::view_details() // prints all the details of the selected image
{
clear_screen();
cout << "\n\t\t\t\t\t\t\t\t\tImage details:";
cout << "\n\t\t\t\t\t\t\t\t\t-------------------------------------";
cout << "\n\t\t\t\t\t\t\t\t\tName: " << current->name << ".jpg";
cout << "\n\t\t\t\t\t\t\t\t\tDate: " << current->date;
cout << "\n\t\t\t\t\t\t\t\t\tSize: " << current->size << "B";
cout << "\n\t\t\t\t\t\t\t\t\t-------------------------------------";
cout << "\n";
current->display();
}
void Gallery::clear_screen()
{
cout << "\033[2J\033[1;1H";
}