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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
| #include "MainWindow.h"
MainWindow::MainWindow() : QWidget()
{
setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
setWindowTitle(tr("Ink Finder"));
Button();
Slots();
}
//############### Private functions ###############
void MainWindow::Button()
{
//###########################################################
//############## Mark chooser window's buttons ##############
//###########################################################
std::ifstream file("database.txt", std::ifstream::in);
//Initialisation of the QSignalMapper
QSignalMapper *markSignalMapper = new QSignalMapper(this);
std::string mark;
for (int n = 0; n < 6; n++)
{
//Determinate coords of each button
int x, y;
if (n % 2 == 0)
x = Init::MARK_COL_1;
else
x = Init::MARK_COL_2;
if (n < 2)
y = Init::MARK_LIN_1;
else if (n < 4)
y = Init::MARK_LIN_2;
else
y = Init::MARK_LIN_3;
mark = ReadInfos(file);
//Setting button's attributes
markButton.push_back(new QPushButton(this));
markButton[n]->setIcon(QIcon(QString::fromStdString("pictures/" + mark + ".png")));
markButton[n]->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
markButton[n]->setFlat(true);
markButton[n]->setGeometry(x, y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
//Connection and mapping of the QSignalMapper
connect(markButton[n], SIGNAL(clicked(bool)), markSignalMapper, SLOT(map()));
markSignalMapper->setMapping(markButton[n], QString::fromStdString(mark));
}
connect(markSignalMapper, SIGNAL(mapped(QString)), this, SIGNAL(markClicked(QString)));
//###########################################################
//############## Type chooser window's buttons ##############
//###########################################################
inkButton = new QPushButton("Jet d'encre", this);
inkButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_1, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
inkButton->setFont(Init::FONT1);
inkButton->hide();
laserButton = new QPushButton("Laser", this);
laserButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_2, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
laserButton->setFont(Init::FONT1);
laserButton->hide();
//###########################################################
//############# Series chooser window's buttons #############
//###########################################################
for (int n = 0; n < 10; n++)
{
//Determinate coords of each button
int x, y;
if (n % 2 == 0)
x = Init::HOME_COL_1;
else
x = Init::HOME_COL_2;
if (n <= 1)
y = Init::HOME_LIN_1;
else if (n <= 3)
y = Init::HOME_LIN_2;
else if (n <= 5)
y = Init::HOME_LIN_3;
else if (n <= 7)
y = Init::HOME_LIN_4;
else
y = Init::HOME_LIN_5;
//Setting button's attributes
seriesButton.push_back(new QPushButton(this));
seriesButton[n]->setFont(Init::FONT6);
seriesButton[n]->hide();
seriesButton[n]->setGeometry(x, y, Init::HOME_WIDTH, Init::HOME_HEIGHT);
}
//###########################################################
//############# Models chooser window's buttons #############
//###########################################################
for (int n = 0; n < 30; n++)
{
//Determinate coords of each button
int x, y;
if (n % 5 == 0)
x = Init::MODEL_COL_1;
else if ((n - 1) % 5 == 0)
x = Init::MODEL_COL_2;
else if ((n - 2) % 5 == 0)
x = Init::MODEL_COL_3;
else if ((n - 3) % 5 == 0)
x = Init::MODEL_COL_4;
else
x = Init::MODEL_COL_5;
if (n <= 4)
y = Init::MODEL_LIN_1;
else if (n <= 9)
y = Init::MODEL_LIN_2;
else if (n <= 14)
y = Init::MODEL_LIN_3;
else if (n <= 19)
y = Init::MODEL_LIN_4;
else if (n <= 24)
y = Init::MODEL_LIN_5;
else
y = Init::MODEL_LIN_6;
//Setting button's attributes
modelsButton.push_back(new QPushButton(this));
modelsButton[n]->setFont(Init::FONT2);
modelsButton[n]->hide();
modelsButton[n]->setGeometry(x, y, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
}
//###########################################################
//################# Common window's buttons #################
//###########################################################
logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
logo->setFlat(true);
markPic = new QPushButton(this);
markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
markPic->setFlat(true);
markPic->hide();
seriesLabel = new QLabel(this);
seriesLabel->setGeometry(Init::SERIES_LABEL_X, Init::SERIES_LABEL_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
seriesLabel->setFont(Init::FONT1);
seriesLabel->setAlignment(Qt::AlignCenter);
seriesLabel->hide();
nextSeriesButton = new QPushButton(QIcon("pictures/next.png"), "", this);
nextSeriesButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
nextSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
nextSeriesButton->setFlat(true);
nextSeriesButton->hide();
previousSeriesButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
previousSeriesButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
previousSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
previousSeriesButton->setFlat(true);
previousSeriesButton->hide();
nextModelsButton = new QPushButton(QIcon("pictures/next.png"), "", this);
nextModelsButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
nextModelsButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
nextModelsButton->setFlat(true);
nextModelsButton->hide();
previousModelsButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
previousModelsButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
previousModelsButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
previousModelsButton->setFlat(true);
previousModelsButton->hide();
exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
exitButton->hide();
//###########################################################
//################# Result window's buttons #################
//###########################################################
for (int n = 0; n < 44; n++)
{
resultsLabel.push_back(new QLabel(this));
//Determinate coords of each label
int x, y;
if (n <= 5)
y = Init::FINAL_LIN_1;
else if (n <= 11)
y = Init::FINAL_LIN_2;
else if (n <= 17)
y = Init::FINAL_LIN_3;
else if (n <= 23)
y = Init::FINAL_LIN_4;
else if (n <= 29)
y = Init::FINAL_LIN_5;
else if (n <= 35)
y = Init::FINAL_LIN_6;
else if (n <= 41)
y = Init::FINAL_LIN_7;
else
y = Init::FINAL_LIN_8;
if (n % 6 == 0)
x = Init::FINAL_COL_1;
else if ((n - 1) % 6 == 0)
{
x = Init::FINAL_COL_2;
if (n != 43)
if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
resultsLabel[n]->setStyleSheet("QLabel { background-color : black; color : white}");
}
else if ((n - 2) % 6 == 0)
{
x = Init::FINAL_COL_3;
if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
resultsLabel[n]->setStyleSheet("QLabel { background-color : magenta}");
}
else if ((n - 3) % 6 == 0)
{
x = Init::FINAL_COL_4;
if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
resultsLabel[n]->setStyleSheet("QLabel { background-color : cyan}");
}
else if ((n - 4) % 6 == 0)
{
x = Init::FINAL_COL_5;
if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
resultsLabel[n]->setStyleSheet("QLabel { background-color : yellow}");
}
else
x = Init::FINAL_COL_6;
//Setting label's attributes
if (n == 0)
resultsLabel[n]->setFont(Init::FONT4);
else
resultsLabel[n]->setFont(Init::FONT2);
resultsLabel[n]->hide();
if (n == 43)
resultsLabel[n]->setGeometry(x, y, Init::FINAL_WIDTH * 5, Init::FINAL_HEIGHT * 2);
else
{
resultsLabel[n]->setGeometry(x, y, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
resultsLabel[n]->setAlignment(Qt::AlignCenter);
}
}
//Setting text to labels
resultsLabel[1]->setText("Noir");
resultsLabel[2]->setText("Magenta");
resultsLabel[3]->setText("Cyan");
resultsLabel[4]->setText("Jaune");
resultsLabel[5]->setText("Type");
resultsLabel[6]->setText("Référence :");
resultsLabel[11]->setText("NORMAL");
resultsLabel[12]->setText("Nombre de pages*");
resultsLabel[18]->setText("Référence :");
resultsLabel[23]->setText("XL");
resultsLabel[24]->setText("Nombre de pages*");
resultsLabel[30]->setText("Référence :");
resultsLabel[36]->setText("Nombre de pages*");
resultsLabel[43]->setText("<i>* Données constructeur (nombre de pages A4)<br>Pour les cartouches photos le nombre de pages estimées est le nombre de photos 10x15</i>");
//###########################################################
//############ Epson Ink Result window's buttons ############
//###########################################################
for (int n = 0; n < 5; n++)
{
epsonInkresultsLabel.push_back(new QLabel(this));
epsonInkresultsLabel[n]->setFont(Init::FONT2);
epsonInkresultsLabel[n]->setAlignment(Qt::AlignCenter);
epsonInkresultsLabel[n]->hide();
}
epsonInkresultsLabel[0]->setText("Capacité");
epsonInkresultsLabel[0]->setGeometry(Init::FINAL_EPSON_COL_1, Init::FINAL_EPSON_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
epsonInkresultsLabel[1]->setText("Noir");
epsonInkresultsLabel[1]->setGeometry(Init::FINAL_EPSON_COL_2 + ((Init::FINAL_EPSON_WIDTH - Init::FINAL_WIDTH) / 2), Init::FINAL_EPSON_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
epsonInkresultsLabel[2]->setText("Couleurs");
epsonInkresultsLabel[2]->setGeometry(Init::FINAL_EPSON_COL_3 + ((Init::FINAL_EPSON_WIDTH - Init::FINAL_WIDTH) / 2), Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
epsonInkresultsLabel[3]->setText("NORMAL");
epsonInkresultsLabel[3]->setGeometry(Init::FINAL_EPSON_COL_1, Init::FINAL_EPSON_LIN_2 + ((Init::FINAL_EPSON_HEIGHT - Init::FINAL_HEIGHT) / 2), Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
epsonInkresultsLabel[4]->setText("XL");
epsonInkresultsLabel[4]->setGeometry(Init::FINAL_EPSON_COL_1, Init::FINAL_EPSON_LIN_3 + ((Init::FINAL_EPSON_HEIGHT - Init::FINAL_HEIGHT) / 2), Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
for (int n = 0; n < 4; n++)
{
int x, y;
if (n % 2 == 0)
x = Init::FINAL_EPSON_COL_2;
else
x = Init::FINAL_EPSON_COL_3;
if (n <= 1)
y = Init::FINAL_EPSON_LIN_2;
else
y = Init::FINAL_EPSON_LIN_3;
//Setting button's attributes
epsonInkresultsButton.push_back(new QPushButton(this));
epsonInkresultsButton[n]->setIconSize(QSize(Init::FINAL_EPSON_WIDTH, Init::FINAL_EPSON_HEIGHT));
epsonInkresultsButton[n]->setFlat(true);
epsonInkresultsButton[n]->hide();
epsonInkresultsButton[n]->setGeometry(x, y, Init::FINAL_EPSON_WIDTH, Init::FINAL_EPSON_HEIGHT);
}
}
void MainWindow::Slots()
{
connect(this, SIGNAL(markClicked(QString)), this, SLOT(RunMark(QString)));
connect(this, SIGNAL(seriesClicked(QString)), this, SLOT(RunSeries(QString)));
connect(this, SIGNAL(modelsClicked(QString)), this, SLOT(RunResults(QString)));
connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
connect(nextModelsButton, SIGNAL(clicked(bool)), this, SLOT(NextModelsButtonClicked()));
connect(previousModelsButton, SIGNAL(clicked(bool)), this, SLOT(PreviousModelsButtonClicked()));
connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
}
//Function that read datas in the database file
std::string MainWindow::ReadInfos(std::ifstream &file)
{
std::string word;
file >> word;
return word;
}
//Function that search datas in the database file
void MainWindow::SearchDatas(std::ifstream &database, std::vector<std::string> &table, std::string series)
{
std::string line;
while(getline(database, line))
{
if(line == series)
{
AssignSeries(database, table);
}
}
}
//Function that generates the series table from datas read from the database file
void MainWindow::AssignSeries(std::ifstream &database, std::vector<std::string> &table)
{
std::string word = "";
while (word != "endlist")
{
word = ReadInfos(database);
if (word != "endlist")
table.push_back(word);
}
}
void MainWindow::SearchResults(std::ifstream &file, std::string series, std::string model)
{
std::string line;
while(getline(file, line))
{
if(line == series)
{
while(getline(file, line))
{
if(line == model)
{
AssignResults(file);
}
}
}
}
}
void MainWindow::SearchEpsonInkResults(std::ifstream &file, std::string series, std::string model)
{
std::string line;
while(getline(file, line))
{
if(line == series)
{
while(getline(file, line))
{
if(line == model)
{
AssignEpsonInkResults(file);
}
}
}
}
}
void MainWindow::AssignResults(std::ifstream &file)
{
resultsLabel[0]->setText(QString::fromStdString(ReadInfos(file)));
for (int n = 7; n < 11; n++)
resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
for (int n = 19; n < 23; n++)
resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
for (int n = 31; n < 35; n++)
resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
for (int n = 13; n < 17; n++)
resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
for (int n = 25; n < 29; n++)
resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
for (int n = 37; n < 41; n++)
resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
}
void MainWindow::AssignEpsonInkResults(std::ifstream &file)
{
for (int n = 0; n < 4; n++)
{
epsonInkresultsButton[n]->setIcon(QIcon(QString::fromStdString("pictures/epson/" + ReadInfos(file) + ".png")));
}
}
//Function that generates the Type window (to choose between ink and laser)
void MainWindow::TypeWindow(std::string mark)
{
myMark = mark;
markPic->setIcon(QIcon(QString::fromStdString("pictures/" + myMark + ".png")));
markPic->show();
//Hiding all mark buttons
for (int n = 0; n < 6; n++)
markButton[n]->hide();
inkButton->show();
laserButton->show();
exitButton->show();
}
//Function that hide all type buttons
void MainWindow::HideTypeButtons()
{
inkButton->hide();
laserButton->hide();
}
//Function that hide all series buttons
void MainWindow::HideSeriesButtons()
{
for (int n = 0; n < 10; n++)
seriesButton[n]->hide();
nextSeriesButton->hide();
previousSeriesButton->hide();
}
//Function that hide all models buttons
void MainWindow::HideModelsButtons()
{
for (int n = 0; n < 30; n++)
modelsButton[n]->hide();
nextModelsButton->hide();
previousModelsButton->hide();
}
//Function that hide all results labels
void MainWindow::HideResultsLabels()
{
for (int n = 0; n < 44; n++)
resultsLabel[n]->hide();
}
void MainWindow::HideEpsonInkResultsElements()
{
for (int n = 0; n < 5; n++)
epsonInkresultsLabel[n]->hide();
for (int n = 0; n < 4; n++)
epsonInkresultsButton[n]->hide();
}
//Function that determines which buttons to display
void MainWindow::ShowSeriesButton(int number)
{
HideSeriesButtons();
//Showing buttons
for (int i = 0; i < number; i++)
seriesButton[i]->show();
//Showing 'next' and 'previous' as it's needed
if (myPage == 1)
{
if (pageNumber > 1)
nextSeriesButton->show();
else
nextSeriesButton->hide();
previousSeriesButton->hide();
}
if (myPage == pageNumber && pageNumber > 1)
{
nextSeriesButton->hide();
previousSeriesButton->show();
}
if (myPage > 1 && myPage < pageNumber)
{
nextSeriesButton->show();
previousSeriesButton->show();
}
}
void MainWindow::ShowModelsButton(int number)
{
HideModelsButtons();
seriesLabel->show();
//Showing buttons
for (int i = 0; i < number; i++)
modelsButton[i]->show();
//Showing 'next' and 'previous' as it's needed
if (myPage == 1)
{
if (pageNumber > 1)
nextModelsButton->show();
else
nextModelsButton->hide();
previousModelsButton->hide();
}
if (myPage == pageNumber && pageNumber > 1)
{
nextModelsButton->hide();
previousModelsButton->show();
}
if (myPage > 1 && myPage < pageNumber)
{
nextModelsButton->show();
previousModelsButton->show();
}
}
void::MainWindow::ShowResultsLabels()
{
for (int n = 0; n < 44; n++)
resultsLabel[n]->show();
}
void MainWindow::ShowEpsonInkResultsElements()
{
for (int n = 0; n < 5; n++)
epsonInkresultsLabel[n]->show();
for (int n = 0; n < 4; n++)
epsonInkresultsButton[n]->show();
}
//Function that generates the Series window (to choose between different series)
void MainWindow::SeriesWindowGeneration(std::string series)
{
myPage = 1;
//Resetting the table
seriesTable.clear();
HideTypeButtons();
//Generating the table
std::ifstream file("database.txt", std::ifstream::in);
SearchDatas(file, seriesTable, series + myType);
SetSeriesInfos();
}
void MainWindow::SetSeriesInfos()
{
int max = pageNumberDetermination(seriesTable, 10);
//Initialisation of the QSignalMapper
QSignalMapper *seriesSignalMapper = new QSignalMapper(this);
//Setting text to button
QString seriesName;
for (int n = 0; n < max; n++)
{
seriesName = QString::fromStdString(seriesTable[n + (10 * (myPage - 1))]);
seriesButton[n]->setText(seriesName);
//Connection and mapping of the QSignalMapper
connect(seriesButton[n], SIGNAL(clicked(bool)), seriesSignalMapper, SLOT(map()));
seriesSignalMapper->setMapping(seriesButton[n], seriesName);
}
connect(seriesSignalMapper, SIGNAL(mapped(QString)), this, SIGNAL(seriesClicked(QString)));
ShowSeriesButton(max);
}
void MainWindow::SetModelsInfos()
{
int max = pageNumberDetermination(modelsTable, 30);
//Initialisation of the QSignalMapper
QSignalMapper *modelsSignalMapper = new QSignalMapper(this);
//Setting text to button
QString modelsName;
for (int n = 0; n < max; n++)
{
modelsName = QString::fromStdString(modelsTable[n + (30 * (myPage - 1))]);
modelsButton[n]->setText(modelsName);
//Connection and mapping of the QSignalMapper
connect(modelsButton[n], SIGNAL(clicked(bool)), modelsSignalMapper, SLOT(map()));
modelsSignalMapper->setMapping(modelsButton[n], modelsName);
}
connect(modelsSignalMapper, SIGNAL(mapped(QString)), this, SIGNAL(modelsClicked(QString)));
ShowModelsButton(max);
}
void MainWindow::SetResultsInfos()
{
seriesLabel->setText(QString::fromStdString(mySeries + "<br>" + myModel));
if (myType == "Ink")
{
resultsLabel[0]->setText("Cartouche");
resultsLabel[35]->setText("PHOTO");
}
else
{
resultsLabel[0]->setText("Toner");
resultsLabel[35]->setText("XXL");
}
std::ifstream file("database.txt", std::ifstream::in);
SearchResults(file, myMark + mySeries + myType + "Series", mySeries + "<br>" + myModel);
ShowResultsLabels();
}
void MainWindow::SetEpsonInkResultsInfos()
{
seriesLabel->setText(QString::fromStdString(mySeries + "<br>" + myModel));
std::ifstream file("database.txt", std::ifstream::in);
SearchEpsonInkResults(file, myMark + mySeries + myType + "Series", mySeries + "<br>" + myModel);
ShowEpsonInkResultsElements();
}
//Function to determine the number of page and buttons to show
int MainWindow::pageNumberDetermination(std::vector<std::string> &table, int buttonNumber)
{
//Calculating number of pages
pageNumber = table.size() / buttonNumber;
//Calculating number of series to show
if ((table.size() % buttonNumber) != 0)
pageNumber++;
if (myPage == pageNumber)
{
if (table.size() % buttonNumber == 0)
return buttonNumber;
else
return table.size() % buttonNumber;
}
else if (myPage < pageNumber)
return buttonNumber;
return 0;
}
//#############################################
//############### Private slots ###############
//#############################################
//Slot that reset the actual window to the home window
void MainWindow::HomeWindow()
{
HideTypeButtons();
HideSeriesButtons();
HideModelsButtons();
HideResultsLabels();
HideEpsonInkResultsElements();
markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
markPic->hide();
exitButton->hide();
seriesLabel->hide();
for (int n = 0; n < markButton.size(); n++)
markButton[n]->show();
}
//Slot that launch the function to generate the Type window by sending the mark
void MainWindow::RunMark(QString mark)
{
TypeWindow(mark.toStdString());
}
//Slot that launch the function to generate the Models window by sending the series
void MainWindow::RunSeries(QString series)
{
HideSeriesButtons();
myPage = 1;
mySeries = series.toStdString();
markPic->setGeometry(Init::MARK_SERIES_X, Init::MARK_SERIES_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
seriesLabel->setText(series);
//Resetting the table
modelsTable.clear();
HideModelsButtons();
//Generating the table
std::ifstream file("database.txt", std::ifstream::in);
SearchDatas(file, modelsTable, myMark + mySeries + myType + "Series");
SetModelsInfos();
}
//Slot that launch the function to generate the Results window by sending the model
void MainWindow::RunResults(QString model)
{
if (myMark == "epson" && myType == "Ink")
RunEpsonInkResults(model);
else
{
myModel = model.toStdString();
HideModelsButtons();
SetResultsInfos();
}
}
//Slot that launch the function to generate the Results window by sending the model
void MainWindow::RunEpsonInkResults(QString model)
{
myModel = model.toStdString();
HideModelsButtons();
SetEpsonInkResultsInfos();
}
//Slots that launch the right functions depending of the mark and the clicked button
void MainWindow::InkClicked()
{
myType = "Ink";
SeriesWindowGeneration(myMark);
}
void MainWindow::LaserClicked()
{
myType = "Laser";
SeriesWindowGeneration(myMark);
}
//Slots that determines the next and previous button's actions
void MainWindow::NextSeriesButtonClicked()
{
myPage++;
SetSeriesInfos();
}
void MainWindow::PreviousSeriesButtonClicked()
{
myPage--;
SetSeriesInfos();
}
void MainWindow::NextModelsButtonClicked()
{
myPage++;
SetModelsInfos();
}
void MainWindow::PreviousModelsButtonClicked()
{
myPage--;
SetModelsInfos();
} |
Partager