git-svn-id: svn://db.shs.com.ru/libs@129 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
67
telegram_test/mainwindow.cpp
Normal file
67
telegram_test/mainwindow.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QDateTime>
|
||||
#include <QBuffer>
|
||||
#include <QGraphicsPixmapItem>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
ui->setupUi(this);
|
||||
connect(bot.getAPI(), SIGNAL(newMessage(TelegramBotAPI::Message)), this, SLOT(printMessage(TelegramBotAPI::Message)));
|
||||
connect(bot.getAPI(), SIGNAL(newFile(TelegramBotAPI::File)), this, SLOT(printImage(TelegramBotAPI::File)));
|
||||
// connect(&bot_timer, SIGNAL(timeout()), &bot, SLOT(updateBot()));
|
||||
// bot_timer.start(1000);
|
||||
bot.setBotToken("281218446:AAEaoS25kKZUevp98U-MKiaPGd2kS18d11g");
|
||||
ui->graphicsView->setScene(new QGraphicsScene());
|
||||
ui->graphicsView->setInteractive(false);
|
||||
ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
// bot.start();
|
||||
}
|
||||
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_1_clicked() {
|
||||
// bot.setBotToken("281218446:AAEaoS25kKZUevp98U-MKiaPGd2kS18d11g");
|
||||
// bot.updateBot();
|
||||
// QImage img(800, 600, QImage::Format_ARGB32);
|
||||
// img.fill(Qt::yellow);
|
||||
// QByteArray ba;
|
||||
// QBuffer buffer(&ba);
|
||||
// buffer.open(QIODevice::WriteOnly);
|
||||
// img.save(&buffer, "PNG");
|
||||
// if (!bot.sendMessageToAll(TelegramBotAPI::Photo, ba, "test.png")) ui->listWidget->addItem("send error");
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pushButton_2_clicked() {
|
||||
if (!ui->lineEdit->text().isEmpty()) {
|
||||
bot.sendMessageToAll(ui->lineEdit->text());
|
||||
ui->listWidget->addItem(QDateTime::currentDateTime().toString() + " #" + bot.getAPI()->botName() + " : " + ui->lineEdit->text());
|
||||
ui->lineEdit->clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::printMessage(TelegramBotAPI::Message msg) {
|
||||
ui->listWidget->addItem(msg.time.toString() + " #" + msg.user_name + " : " + msg.text);
|
||||
lid = msg.chat_id;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::printImage(TelegramBotAPI::File file) {
|
||||
QImage img;
|
||||
if (img.loadFromData(file.data)) {
|
||||
QPixmap pix = QPixmap::fromImage(img);
|
||||
QListWidgetItem * lwi = new QListWidgetItem(QIcon(pix), file.filename);
|
||||
ui->listWidget->addItem(lwi);
|
||||
ui->graphicsView->scene()->addPixmap(pix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_lineEdit_editingFinished() {
|
||||
on_pushButton_2_clicked();
|
||||
}
|
||||
Reference in New Issue
Block a user