Guest User

XML

a guest
Jul 17th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.21 KB | None | 0 0
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QMenu>
  4. #include <QSystemTrayIcon>
  5. #include <QVBoxLayout>
  6. #include <QHBoxLayout>
  7. #include <QLineEdit>
  8. #include <QTextBrowser>
  9.  
  10. MainWindow::MainWindow(QWidget *parent) :
  11.     QMainWindow(parent),
  12.     ui(new Ui::MainWindow)
  13. {
  14.     ui->setupUi(this);
  15.     this -> setTrayIconActions();
  16.     this -> showTrayIcon();
  17.     connect(ui->find_btn,SIGNAL(clicked()),this,SLOT(showText()));
  18.     connect(ui->request_btn,SIGNAL(clicked()),this,SLOT(sendRequest()));
  19.  
  20. }
  21.  
  22. MainWindow::~MainWindow()
  23. {
  24.     delete ui;
  25. }
  26.  
  27. void MainWindow::showTrayIcon()
  28. {
  29.     //Создаем экземпляр класса и задаем свойства
  30.     trayIcon = new QSystemTrayIcon(this);
  31.     QIcon trayImage(":/imgages/ABills.png");
  32.     trayIcon->setIcon(trayImage);
  33.     trayIcon->setContextMenu(trayIconMenu);
  34.  
  35.     // Подключаем обработчик клика по иконке...
  36.     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
  37.  
  38.     // Выводим значок...
  39.     trayIcon -> show();
  40. }
  41.  
  42. void MainWindow::trayActionExecute()
  43. {
  44.     this->showNormal();
  45. }
  46.  
  47. void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
  48. {
  49.     switch (reason)
  50.     {
  51.  
  52.         case QSystemTrayIcon::DoubleClick:
  53.         case QSystemTrayIcon::Trigger:
  54.             this -> showNormal();
  55.             break;
  56.         default:
  57.             break;
  58.     }
  59. }
  60.  
  61. void MainWindow::setTrayIconActions()
  62. {
  63.     // Setting actions...
  64.     minimizeAction = new QAction("Свернуть", this);
  65.     restoreAction = new QAction("Восстановить", this);
  66.     quitAction = new QAction("Выход", this);
  67.  
  68.     // Connecting actions to slots...
  69.     connect (minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
  70.     connect (restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
  71.     connect (quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
  72.  
  73.     // Setting system tray's icon menu...
  74.     trayIconMenu = new QMenu(this);
  75.     trayIconMenu -> addAction (minimizeAction);
  76.     trayIconMenu -> addAction (restoreAction);
  77.     trayIconMenu -> addAction (quitAction);
  78. }
  79.  
  80. void MainWindow::changeEvent(QEvent *event)
  81. {
  82.     QMainWindow::changeEvent(event);
  83.     if (event -> type() == QEvent::WindowStateChange)
  84.     {
  85.         if (isMinimized())
  86.         {
  87.             this -> hide();
  88.         }
  89.     }
  90. }
  91.  
  92. void MainWindow::showText()
  93. {
  94.     QString txt = ui->phone_edit->text();
  95.     abills = "https://192.168.0.120:9443/admin/index.cgi?qindex=7&search_form=1&search=1&type=11&header=1&xml=1&PHONE=";
  96.     abills+=txt;
  97.     url_req = abills;
  98.     ui->url_shower->setText(abills);
  99. }
  100.  
  101. void MainWindow::sendRequest()
  102. {
  103.    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
  104.    connect(manager, SIGNAL(finished(reply)),this, SLOT(replyFinished(reply)));
  105.    manager->get(QNetworkRequest(url_req));
  106. }
  107.  
  108. void MainWindow::replyFinished(QNetworkReply * reply)
  109. {
  110.     QNetworkAccessManager *manager = new QNetworkAccessManager(this);
  111.     reply = manager->get(QNetworkRequest(url_req));
  112.     data = reply->readAll();
  113.     ui->data_show->setText(data);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment