Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. textEdit::textEdit(QTextEdit *parent) : QTextEdit(parent) {
  5. }
  6.  
  7. void textEdit::clickedOnRecipe(const QModelIndex& index) {
  8. QDir recepieDirectory("D:/RECIPES");
  9. QStringList recipeName = recepieDirectory.entryList(QStringList("*txt"));
  10. //qDebug() << recipeName;
  11. QFile file("D:/RECIPES/" + recipeName[index.row()]);
  12. file.open(QIODevice::ReadOnly);
  13. //qDebug() << "D:/RECIPES/" + strlst[index.row()];
  14. QByteArray fileData = file.readAll();
  15. setText(fileData);
  16. file.close();
  17. }
  18.  
  19. culinaryGuide::culinaryGuide(QWidget* parent) : QWidget(parent){
  20. text1 = new QLabel("Choose one of recipes : ");
  21. text2 = new QLabel("Recipes : ");
  22.  
  23. findButton = new QPushButton("Find");
  24. findButton->setFixedSize(40,40);
  25.  
  26. clearButton = new QPushButton("Clear");
  27. clearButton->setFixedSize(40,40);
  28.  
  29. searchLine = new QLineEdit;
  30. searchLine->setFixedSize(100,40);
  31.  
  32. recipe = new textEdit;
  33. recipe->setFixedSize(1000,750);
  34.  
  35. recepieDirectory = new QDir("D:/RECIPES");
  36.  
  37. recipeName = recepieDirectory->entryList(QStringList("*.txt"));
  38.  
  39. listView = new QListView;
  40. model = new QFileSystemModel;
  41. model->setRootPath("D:/RECIPES");
  42. listView->setModel(model);
  43. listView->setRootIndex(model->index("D:/RECIPES"));
  44.  
  45. QHBoxLayout *horL = new QHBoxLayout;
  46. QVBoxLayout *verL = new QVBoxLayout;
  47. QSplitter *splitter = new QSplitter(Qt::Horizontal);
  48.  
  49. splitter->addWidget(listView);
  50. splitter->addWidget(recipe);
  51. horL->addWidget(text1);
  52. horL->addWidget(text2);
  53. horL->addWidget(searchLine);
  54. horL->addWidget(findButton);
  55. horL->addWidget(clearButton);
  56. verL->addLayout(horL);
  57. verL->addWidget(splitter);
  58. setLayout(verL);
  59. resize(1600,750);
  60.  
  61. connect(listView,SIGNAL(clicked(const QModelIndex&)),recipe,SLOT(clickedOnRecipe(const QModelIndex&)));
  62. connect(findButton,SIGNAL(clicked()),SLOT(find()));
  63. connect(clearButton,SIGNAL(clicked()),SLOT(clearButtonClicked()));
  64. }
  65.  
  66. void culinaryGuide::find(){
  67. foreach(QString temp,recipeName) {
  68. if(temp == (searchLine->text() + ".txt")) {
  69. model->setNameFilters(QStringList(searchLine->text() + ".txt"));
  70. }
  71. }
  72. }
  73.  
  74. void culinaryGuide::clearButtonClicked() {
  75. searchLine->setText("");
  76. model->setNameFilters(QStringList("*.txt"));
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement