1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

update frame

This commit is contained in:
tianduanrui 2017-08-15 15:49:51 +08:00
parent c8fc0317cc
commit 1fe6ff4381
13 changed files with 1037 additions and 18 deletions

View File

@ -0,0 +1,46 @@
#include "qqtpassworddialog.h"
#include "ui_qqtpassworddialog.h"
QQTPasswordDialog::QQTPasswordDialog(QWidget *parent) :
QQTDialog(parent),
ui(new Ui::QQTPasswordDialog)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, false);
/*
* dialog关闭 show的功能强大起来 使
*/
setWindowModality(Qt::WindowModal);
ui->lineEdit_ssid_password->setEchoMode(QLineEdit::Password);
ui->pushButton_ssid_connect->setEnabled(false);
connect(ui->pushButton_ssid_connect, SIGNAL(clicked()), this, SLOT(connectClicked()));
connect(ui->lineEdit_ssid_password, SIGNAL(textChanged(QString)), SLOT(btnEnabled(QString)));
connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
}
QQTPasswordDialog::~QQTPasswordDialog()
{
delete ui;
}
void QQTPasswordDialog::setWifiName(QString name)
{
ui->label_ssid_name->setText(name);
}
QString QQTPasswordDialog::wifiPwd()
{
return ui->lineEdit_ssid_password->text();
}
void QQTPasswordDialog::connectClicked()
{
emit connectClicked(ui->lineEdit_ssid_password->text());
accept();
}
void QQTPasswordDialog::btnEnabled(QString pas)
{
bool enable = pas.length()<8?false:true;
ui->pushButton_ssid_connect->setEnabled(enable);
}

31
frame/qqtpassworddialog.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef QQTPASSWORDDIALOG_H
#define QQTPASSWORDDIALOG_H
#include "qqtdialog.h"
namespace Ui {
class QQTPasswordDialog;
}
class QQTPasswordDialog : public QQTDialog
{
Q_OBJECT
public:
explicit QQTPasswordDialog(QWidget *parent = 0);
~QQTPasswordDialog();
void setWifiName(QString name);
QString wifiPwd();
signals:
void connectClicked(QString password);
private slots:
void connectClicked();
void btnEnabled(QString);
private:
Ui::QQTPasswordDialog *ui;
};
#endif // QQTPASSWORDDIALOG_H

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QQTPasswordDialog</class>
<widget class="QQTDialog" name="QQTPasswordDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>413</width>
<height>202</height>
</rect>
</property>
<property name="windowTitle">
<string>Password</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>9</x>
<y>30</y>
<width>61</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>WIFI:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_ssid_password">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>391</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QQTPushButton" name="pushButton_ssid_connect">
<property name="geometry">
<rect>
<x>270</x>
<y>150</y>
<width>85</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Connect</string>
</property>
</widget>
<widget class="QLabel" name="label_ssid_name">
<property name="geometry">
<rect>
<x>80</x>
<y>31</y>
<width>311</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>SSID NAME</string>
</property>
</widget>
<widget class="QPushButton" name="btnCancel">
<property name="geometry">
<rect>
<x>50</x>
<y>150</y>
<width>85</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>QQTPushButton</class>
<extends>QPushButton</extends>
<header>qqtpushbutton.h</header>
</customwidget>
<customwidget>
<class>QQTDialog</class>
<extends>QWidget</extends>
<header>qqtdialog.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

323
frame/qqtpreviewwidget.cpp Normal file
View File

@ -0,0 +1,323 @@
#include "qqtpreviewwidget.h"
#include "ui_qqtpreviewwidget.h"
QQTPreviewWidget::QQTPreviewWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::QQTPreviewWidget)
{
ui->setupUi(this);
memset(&sinfo, 0, sizeof(struct sensor_info));
pre_bpp = 16;
rate = 15; /* default to 15fps */
addr = 0;
phys = 0;
pre_size.w = 720;
pre_size.h = 480;
fd = 0;
memset( & pre_memory, 0, sizeof(struct camera_memory));
memset( & pre_buf, 0, sizeof(struct camera_buffer));
memset( & pre_size, 0, sizeof(struct frm_size));
tlb_base_phys = 0;
format = HAL_PIXEL_FORMAT_YCbCr_422_I;
bFullScreen = false;
m_parent = parent;
timer = new QTimer(this);
timer->setSingleShot(false);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
}
QQTPreviewWidget::~QQTPreviewWidget()
{
delete ui;
}
int QQTPreviewWidget::play()
{
/*
*
*/
dmmu_init();
dmmu_get_page_table_base_phys(&tlb_base_phys);
fd = ::open("/dev/cim", O_RDWR); //av
if (fd < 0) {
qDebug() << "Open device fail\n";
}
ioctl(fd, CIMIO_SELECT_SENSOR, sinfo.sensor_id);
ioctl(fd, CIMIO_GET_SENSORINFO, &sinfo);
ioctl(fd, CIMIO_SET_TLB_BASE, tlb_base_phys);//?????????
int i = 0;
if(pre_buf.common && pre_buf.common->data)
{
dmmu_unmap_user_memory(&(pre_buf.dmmu_info));
free(pre_buf.common->data);
}
pre_buf.fd = fd;
pre_buf.nr = 5;
pre_buf.size = pre_size.w * pre_size.h * 3;
pre_buf.common = &pre_memory;
pre_buf.common->size = pre_buf.size * pre_buf.nr;
pre_buf.common->data = memalign(4096, pre_buf.size * pre_buf.nr);
memset(pre_buf.common->data, 0xa5, (pre_buf.size * pre_buf.nr));
if (pre_buf.common->data == NULL)
{
printf("==<%s L%d: null pointer!\n", __func__, __LINE__);
return false;
}
pre_buf.paddr = 0;
pre_buf.dmmu_info.vaddr = pre_buf.common->data;
pre_buf.dmmu_info.size = pre_buf.common->size;
for (i = 0; i < (int)(pre_buf.common->size); i += 0x1000)
{
((uint8_t*)(pre_buf.common->data))[i] = 0xff;
}
((uint8_t*)(pre_buf.common->data))[pre_buf.common->size - 1] = 0xff;
dmmu_map_user_memory(&(pre_buf.dmmu_info));
for (i= 0; i < pre_buf.nr; ++i) {
pre_buf.yuvMeta[i].index = i;
pre_buf.yuvMeta[i].width = pre_size.w;
pre_buf.yuvMeta[i].height = pre_size.h;
pre_buf.yuvMeta[i].format = format;
pre_buf.yuvMeta[i].count = pre_buf.nr;
#ifdef __LINUX64__
pre_buf.yuvMeta[i].yAddr = (int64_t)pre_buf.common->data + (pre_buf.size) * i;
#else
pre_buf.yuvMeta[i].yAddr = (int32_t)pre_buf.common->data + (pre_buf.size) * i;
#endif
pre_buf.yuvMeta[i].yPhy = pre_buf.paddr + i * (pre_buf.size);
if (pre_buf.yuvMeta[i].format == HAL_PIXEL_FORMAT_YCbCr_422_I) { //yuv422 packed
pre_buf.yuvMeta[i].uAddr = pre_buf.yuvMeta[i].yAddr;
pre_buf.yuvMeta[i].vAddr = pre_buf.yuvMeta[i].uAddr;
pre_buf.yuvMeta[i].uPhy = pre_buf.yuvMeta[i].yPhy;
pre_buf.yuvMeta[i].vPhy = pre_buf.yuvMeta[i].uPhy;
pre_buf.yuvMeta[i].yStride = pre_buf.yuvMeta[i].width<<1;
pre_buf.yuvMeta[i].uStride = pre_buf.yuvMeta[i].yStride;
pre_buf.yuvMeta[i].vStride = pre_buf.yuvMeta[i].yStride;
} else if (pre_buf.yuvMeta[i].format == HAL_PIXEL_FORMAT_JZ_YUV_420_P) { //yuv420 planar
pre_buf.yuvMeta[i].uAddr = pre_buf.yuvMeta[i].yAddr + pre_size.w * pre_size.h;
pre_buf.yuvMeta[i].vAddr = pre_buf.yuvMeta[i].uAddr + pre_size.w * pre_size.h / 4;
pre_buf.yuvMeta[i].uPhy = pre_buf.yuvMeta[i].yPhy + pre_size.w * pre_size.h;
pre_buf.yuvMeta[i].vPhy = pre_buf.yuvMeta[i].uPhy + pre_size.w * pre_size.h / 4;
pre_buf.yuvMeta[i].yStride = pre_buf.yuvMeta[i].width<<1;
pre_buf.yuvMeta[i].uStride = pre_buf.yuvMeta[i].width / 2;
pre_buf.yuvMeta[i].vStride = pre_buf.yuvMeta[i].width / 2;
} else if (pre_buf.yuvMeta[i].format == HAL_PIXEL_FORMAT_RAW_SENSOR) { //raw bayer
pre_buf.yuvMeta[i].uAddr = pre_buf.yuvMeta[i].yAddr + pre_size.w * pre_size.h;
pre_buf.yuvMeta[i].vAddr = pre_buf.yuvMeta[i].uAddr;
pre_buf.yuvMeta[i].uPhy = pre_buf.yuvMeta[i].yPhy;
pre_buf.yuvMeta[i].vPhy = pre_buf.yuvMeta[i].uPhy;
pre_buf.yuvMeta[i].yStride = pre_buf.yuvMeta[i].width;
pre_buf.yuvMeta[i].uStride = pre_buf.yuvMeta[i].yStride;
pre_buf.yuvMeta[i].vStride = pre_buf.yuvMeta[i].yStride;
}
}
ioctl(fd, CIMIO_SET_PREVIEW_FMT, format);
ioctl(fd, CIMIO_SET_PREVIEW_SIZE, &pre_size);
ioctl(fd, CIMIO_SET_PREVIEW_MEM, (unsigned long)(pre_buf.yuvMeta));
ioctl(fd, CIMIO_START_PREVIEW);
pp = (unsigned char *)malloc(pre_size.w * pre_size.h * 3 * sizeof(char));
frame = new QImage(pp, pre_size.w, pre_size.h, QImage::Format_RGB888);
timer->start(100);
return fd;
}
int QQTPreviewWidget::close()
{
bool ret = false;
if(fd <= 0)
printf("fd < 0\n");
ret = ioctl(fd, CIMIO_SHUTDOWN);
::close(fd);
fd = 0;
dmmu_unmap_user_memory(&(pre_buf.dmmu_info));
dmmu_deinit();
memset(pre_buf.yuvMeta, 0, pre_buf.nr * sizeof (CameraYUVMeta));
pre_buf.size = 0;
pre_buf.nr = 0;
pre_buf.paddr = 0;
pre_buf.fd = -1;
if((pre_buf.common != NULL) && (pre_buf.common->data != NULL)) {
free(pre_buf.common->data);
pre_buf.common->data = NULL;
}
phys = 0;
timer->stop();
free(pp);
delete frame;
return ret;
}
int QQTPreviewWidget::convert_yuv_to_rgb_pixel(int y, int u, int v)
{
unsigned int pixel32 = 0;
unsigned char *pixel = (unsigned char *)&pixel32;
int r, g, b;
b = y + ((443 * (u - 128)) >> 8);
b = (b < 0) ? 0 : ((b > 255 ) ? 255 : b);
g = y - ((179 * (v - 128) + 86 * (u - 128)) >> 8);
g = (g < 0) ? 0 : ((g > 255 ) ? 255 : g);
r = y + ((351 * (v - 128)) >> 8);
r = (r < 0) ? 0 : ((r > 255 ) ? 255 : r);
pixel[0] = r;
pixel[1] = g;
pixel[2] = b;
return pixel32;
}
int QQTPreviewWidget::convert_yuv_to_rgb_buffer(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
{
unsigned int in, out = 0;
unsigned int pixel_16;
unsigned char pixel_24[3];
unsigned int pixel32;
int y0, u, y1, v;
for(in = 0; in < width * height * 2; in += 4) {
pixel_16 =
yuv[in + 3] << 24 |
yuv[in + 2] << 16 |
yuv[in + 1] << 8 |
yuv[in + 0];
y0 = (pixel_16 & 0x000000ff);
u = (pixel_16 & 0x0000ff00) >> 8;
y1 = (pixel_16 & 0x00ff0000) >> 16;
v = (pixel_16 & 0xff000000) >> 24;
pixel32 = convert_yuv_to_rgb_pixel(y0, u, v);
pixel_24[0] = (pixel32 & 0x000000ff);
pixel_24[1] = (pixel32 & 0x0000ff00) >> 8;
pixel_24[2] = (pixel32 & 0x00ff0000) >> 16;
rgb[out++] = pixel_24[0];
rgb[out++] = pixel_24[1];
rgb[out++] = pixel_24[2];
pixel32 = convert_yuv_to_rgb_pixel(y1, u, v);
pixel_24[0] = (pixel32 & 0x000000ff);
pixel_24[1] = (pixel32 & 0x0000ff00) >> 8;
pixel_24[2] = (pixel32 & 0x00ff0000) >> 16;
rgb[out++] = pixel_24[0];
rgb[out++] = pixel_24[1];
rgb[out++] = pixel_24[2];
}
return 0;
}
void QQTPreviewWidget::paintEvent(QPaintEvent *)
{
if(fd <= 0)
return;
QStylePainter painter(this);
/*
* 线 log证明
*/
addr = ioctl(fd, CIMIO_GET_FRAME);
p = (uchar*)addr;
/*
* yuv缺少alpha
*/
convert_yuv_to_rgb_buffer(p, pp, pre_size.w, pre_size.h);
//frame->loadFromData((uchar *)pp, w * h * 3 * sizeof(char));
/*
*
*/
QRect srcRect(2, 6, pre_size.w, pre_size.h);
QRect dstRect = rect();
painter.scale(1.01, 1.02);
/*
* OK
*/
painter.drawImage(dstRect, *frame, srcRect );
//painter.drawPixmap(dstRect,QPixmap::fromImage(*frame,Qt::AutoColor),srcRect);;
/*
* OK
*/
//painter.drawItemPixmap(srcRect, Qt::AlignCenter, QPixmap::fromImage(*frame,Qt::AutoColor));
/*
* 30ms
*/
//update();
}
void QQTPreviewWidget::mousePressEvent(QMouseEvent *e)
{
static bool bGInit = false;
if(!bGInit && !bFullScreen)
{
flags = windowFlags();
flags |= Qt::FramelessWindowHint;
geome = geometry();
bGInit = true;
}
#ifdef __MIPS_LINUX__
//pline() << e->pos() << e->globalPos();
if(e->pos().x() < 0 || e->pos().y() < 0 ||
e->pos().x() > geome.width() || e->pos().y() > geome.height())
{
//在mips板上全屏返回的时候点击其他位置会多响应一次在此处过滤。
pline() << "warning!";
Q_UNUSED(e);
return;
}
#endif
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_NoMousePropagation, true);
setAttribute(Qt::WA_OpaquePaintEvent, true);
if(bFullScreen)
{
flags ^= Qt::Window;
flags |= Qt::Widget;
setParent(m_parent, flags);
setGeometry(geome);
show();
bFullScreen = false;
}
else
{
int QQT_SCRN_WIDTH = QApplication::desktop()->availableGeometry().width();
int QQT_SCRN_HEIGHT = QApplication::desktop()->availableGeometry().height();
flags ^= Qt::Widget;
flags |= Qt::Window;
setParent(0, flags);
setGeometry(0, 0, QQT_SCRN_WIDTH, QQT_SCRN_HEIGHT);
show();
bFullScreen = true;
}
pline() << flags;
QWidget::mousePressEvent(e);
}

72
frame/qqtpreviewwidget.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef QPREVIEWUI_H
#define QPREVIEWUI_H
#include "qqtgui-qt.h"
#include "qqtlinux.h"
#include "qqtdefine.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "graphics.h"
#include "dmmu.h"
#include "hal.h"
#include "jz_cim.h"
#ifdef __cplusplus
}
#endif /* __cplusplus */
namespace Ui {
class QQTPreviewWidget;
}
class QQTPreviewWidget : public QWidget
{
Q_OBJECT
public:
explicit QQTPreviewWidget(QWidget *parent = 0);
~QQTPreviewWidget();
int play();
int close();
private:
Ui::QQTPreviewWidget *ui;
struct sensor_info sinfo;
int pre_bpp;
int rate; /* default to 15fps */
unsigned int addr;
unsigned int phys;
int fd;
int format;
struct camera_memory pre_memory;
struct camera_buffer pre_buf;
struct frm_size pre_size;
unsigned int tlb_base_phys;
uchar *pp;
uchar * p;
QImage *frame;
QTimer *timer;
bool bFullScreen;
QWidget* m_parent;
QRect geome;
Qt::WindowFlags flags;
int convert_yuv_to_rgb_pixel(int y, int u, int v);
int convert_yuv_to_rgb_buffer(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height);
// QWidget interface
protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *e);
};
#endif // QPREVIEWUI_H

41
frame/qqtpreviewwidget.ui Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QQTPreviewWidget</class>
<widget class="QWidget" name="QQTPreviewWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>498</width>
<height>202</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>QQT</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>199</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,65 @@
#include "qqtprogressdialog.h"
#include "ui_qqtprogressdialog.h"
#include "qqtdefine.h"
#include "qqtobjectfactory.h"
QQTProgressDialog::QQTProgressDialog(QWidget *parent) :
QQTDialog(parent),
ui(new Ui::QQTProgressDialog)
{
ui->setupUi(this);
bar = ui->widgetBar;
bar->setRange(0, 100);
bar->setValue(0);
connect(ui->btnCancel, SIGNAL(clicked()),
this, SLOT(reject()));
//setFixedWidth(260);
#ifdef __QQTWIDGETS_K1160__
setFixedSize(526, 283);
bar->setFixedSize(481, 31);
bar->move(20, 50);
ui->btnCancel->setText("");
ui->btnCancel->setFixedSize(104, 40);
ui->btnCancel->iconTable().initNormal("./skin/default/bt_back_normal.png",
"./skin/default/bt_back_press.png" );
ui->btnCancel->iconTable().initOther("./skin/default/bt_back_hover.png",
"./skin/default/bt_back_disable.png");
ui->widgetBar->setPixMap("./skin/default/bk_progress_background.png",
"./skin/default/bk_progress_chunk.png");
#endif
QQTObjectFactory::registerObject(this);
QQTObjectFactory::registerObject(ui->btnCancel);
}
QQTProgressDialog::~QQTProgressDialog()
{
delete ui;
}
void QQTProgressDialog::initAll()
{
bar->setRange(0, 100);
bar->setValue(0);
}
void QQTProgressDialog::setRange(int min, int max)
{
bar->setRange(min, max);
}
void QQTProgressDialog::setContent(QString content)
{
ui->label->setText(content);
}
void QQTProgressDialog::setValue(int value)
{
bar->setValue(value);
}

31
frame/qqtprogressdialog.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef QPROGRESSWINDOW_H
#define QPROGRESSWINDOW_H
#include "qqtdialog.h"
#include "qqtprogressbar.h"
namespace Ui {
class QQTProgressDialog;
}
class QQTProgressDialog : public QQTDialog
{
Q_OBJECT
public:
explicit QQTProgressDialog(QWidget *parent = 0);
~QQTProgressDialog();
void initAll();
void setRange(int min, int max);
void setContent(QString content);
public slots:
void setValue(int value);
private:
Ui::QQTProgressDialog *ui;
QQTProgressBar* bar;
};
#endif // QPROGRESSWINDOW_H

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QQTProgressDialog</class>
<widget class="QQTDialog" name="QQTProgressDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>526</width>
<height>283</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QQTPushButton" name="btnCancel">
<property name="geometry">
<rect>
<x>220</x>
<y>220</y>
<width>85</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QQTProgressBar" name="widgetBar" native="true">
<property name="geometry">
<rect>
<x>20</x>
<y>50</y>
<width>481</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>100</y>
<width>281</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Progressing</string>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>QQTPushButton</class>
<extends>QPushButton</extends>
<header>qqtpushbutton.h</header>
</customwidget>
<customwidget>
<class>QQTDialog</class>
<extends>QWidget</extends>
<header>qqtdialog.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QQTProgressBar</class>
<extends>QWidget</extends>
<header>qqtprogressbar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

147
frame/qqtwifiwidget.cpp Normal file
View File

@ -0,0 +1,147 @@
#include "qqtwifiwidget.h"
#include "ui_qqtwifiwidget.h"
#include "qqtlinux.h"
#include "qqtdefine.h"
#include "qqtethenetmanager.h"
#include "qqtmsgbox.h"
void QQTWIFIIDTextDelegate::drawCheck(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, Qt::CheckState state) const
{
#if 0
if (!rect.isValid())
return;
QStyleOptionViewItem opt(option);
opt.rect = rect;
opt.state = opt.state & ~QStyle::State_HasFocus;
switch (state) {
case Qt::Unchecked:
opt.state |= QStyle::State_Off;
break;
case Qt::PartiallyChecked:
opt.state |= QStyle::State_NoChange;
break;
case Qt::Checked:
opt.state |= QStyle::State_On;
break;
}
QApplication::style()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter);
#else
QItemDelegate::drawCheck(painter, option, rect, state);
#endif
}
void QQTWIFIIDTextDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
{
if("COMPLETED" == text)
painter->drawImage(rect, QImage("./skin/default/bk_sel.png"));
}
QQTWIFIWidget::QQTWIFIWidget(QWidget *parent) :
QQTTableView(parent),
ui(new Ui::QQTWIFIWidget)
{
ui->setupUi(this);
connect(this, SIGNAL(clicked(QModelIndex)),
this, SLOT(clickWIFI()), Qt::QueuedConnection);
m_pass = new QQTPasswordDialog(this);
m_pManager = QQTEthenetManager::Instance(this);
connect(m_pManager, SIGNAL(sigRefreshed()), this, SLOT(wifiRefreshed()));
m_model = new QQTStandardItemModel(this);
m_model->setColumnCount(ESSID_MAX);
setModel(m_model);
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers);
horizontalHeader()->setHidden(true);
verticalHeader()->setHidden(true);
resizeColumnsToContents();
horizontalHeader()->setStretchLastSection(true);
setShowGrid(true);
#ifdef __MIPS_LINUX__
setFocusPolicy(Qt::NoFocus);
#endif
dg = new QQTWIFIIDTextDelegate(this);
setItemDelegateForColumn(ESSID_STATUS, dg);
for(int i = ESSID_TYPE; i < ESSID_MAX; i++)
setColumnHidden(i, true);
#ifdef __QT5__
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
#else
horizontalHeader()->setResizeMode(0, QHeaderView::Fixed);
#endif
setColumnWidth(ESSID_STATUS, 40);
}
QQTWIFIWidget::~QQTWIFIWidget()
{
delete ui;
}
TWifi QQTWIFIWidget::currentWifi()
{
return m_pManager->currentWifi();
}
bool QQTWIFIWidget::setCurrentWifi(QString bssid_mac, QString password)
{
return m_pManager->setCurrentWifi(bssid_mac, password);
}
void QQTWIFIWidget::wifiRefreshed()
{
int row = 0;
m_model->removeRows(row, m_model->rowCount());
QList<TWifi>& list = m_pManager->wifiList();
m_model->insertRows(row, list.size());
for(QList<TWifi>::Iterator it = list.begin();
it != list.end(); it++)
{
TWifi wifi = *(TWifi*)(&*it);
for(int i = ESSID_STATUS; i < ESSID_MAX; i++)
m_model->setData(m_model->index(row, i), wifi[i]);
row++;
}
m_model->submit();
}
void QQTWIFIWidget::clickWIFI()
{
QString name = m_model->data(m_model->index(currentIndex().row(), ESSID_NAME)).toString();
QString encryt = m_model->data(m_model->index(currentIndex().row(), ESSID_ENCRYP)).toString();
QString type = m_model->data(m_model->index(currentIndex().row(), ESSID_TYPE)).toString();
QString mac = m_model->data(m_model->index(currentIndex().row(), ESSID_BSSID)).toString();
QQTEthenetManager::Instance()->setRefresh(false);
do
{
if("YES" == encryt)
{
m_pass->setWifiName(name);
if(QQTPasswordDialog::Rejected == m_pass->exec())
break;
}
bool ok = setCurrentWifi(mac, m_pass->wifiPwd());
pline() << ok;
if(!ok)
{
QQTMsgBox::warning(this, tr("Password error"));
break;
}
pline() << name << encryt << m_pass->wifiPwd();
}while(0);
QQTEthenetManager::Instance()->setRefresh();
}

58
frame/qqtwifiwidget.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef QQTWIFIWIDGET_H
#define QQTWIFIWIDGET_H
#include "qqtstandarditemmodel.h"
#include "qqtgui-qt.h"
#include "qqtgui.h"
#include "qqtpassworddialog.h"
#include <QItemDelegate>
#include <QStylePainter>
#include "qqtdefine.h"
class QQTWIFIIDTextDelegate : public QItemDelegate
{
Q_OBJECT
public:
QQTWIFIIDTextDelegate(QObject *parent = 0): QItemDelegate(parent), parent(parent) { }
private:
QObject* parent;
// QItemDelegate interface
protected:
void drawCheck(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, Qt::CheckState state) const;
// QItemDelegate interface
protected:
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const;
};
namespace Ui {
class QQTWIFIWidget;
}
class QQTWIFIWidget : public QQTTableView
{
Q_OBJECT
public:
explicit QQTWIFIWidget(QWidget *parent = 0);
~QQTWIFIWidget();
private slots:
void clickWIFI();
void wifiRefreshed();
protected:
TWifi currentWifi();
bool setCurrentWifi(QString bssid_mac, QString password = "");
private:
QQTEthenetManager* m_pManager;
QQTWIFIIDTextDelegate* dg;
private:
Ui::QQTWIFIWidget *ui;
QQTStandardItemModel* m_model;
QQTPasswordDialog* m_pass;
};
#endif // QQTWIFIWIDGET_H

21
frame/qqtwifiwidget.ui Normal file
View File

@ -0,0 +1,21 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>QQTWIFIWidget</class>
<widget name="QQTWIFIWidget" class="QQTTableView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>

View File

@ -16,7 +16,8 @@ DEFINES += _TTY_POSIX_
INCLUDEPATH += $$PWD \ INCLUDEPATH += $$PWD \
$$PWD/customplot \ $$PWD/customplot \
$$PWD/pluginwatcher \ $$PWD/pluginwatcher \
$$PWD/dmmu $$PWD/dmmu \
$$PWD/frame
QT_KIT = $$(QKIT) QT_KIT = $$(QKIT)
@ -69,19 +70,43 @@ unix {
} else { } else {
SOURCES += $$PWD/pluginwatcher/qdevicewatcher_linux.cpp SOURCES += $$PWD/pluginwatcher/qdevicewatcher_linux.cpp
} }
#frame
SOURCES += $$PWD/frame/qqtprogressdialog.cpp \
$$PWD/frame/qqtpassworddialog.cpp \
$$PWD/frame/qqtpreviewwidget.cpp \
$$PWD/frame/qqtwifiwidget.cpp
HEADERS += $$PWD/frame/qqtprogressdialog.h \
$$PWD/frame/qqtpassworddialog.h \
$$PWD/frame/qqtpreviewwidget.h \
$$PWD/frame/qqtwifiwidget.h
FORMS += $$PWD/frame/qqtprogressdialog.ui \
$$PWD/frame/qqtpassworddialog.ui \
$$PWD/frame/qqtpreviewwidget.ui \
$$PWD/frame/qqtwifiwidget.ui
#dmmu
SOURCES += $$PWD/dmmu/dmmu.c
HEADERS += $$PWD/dmmu/dmmu.h \ HEADERS += $$PWD/dmmu/dmmu.h \
$$PWD/dmmu/jz_cim.h \ $$PWD/dmmu/jz_cim.h \
$$PWD/dmmu/graphics.h \ $$PWD/dmmu/graphics.h \
$$PWD/dmmu/hal.h \ $$PWD/dmmu/hal.h
$$PWD/qqtethenetmanager.h \ #
#linux base type SOURCES += $$PWD/qqtethenetmanager.cpp
HEADERS += $$PWD/qqtethenetmanager.h \
$$PWD/qqtlinux.h $$PWD/qqtlinux.h
SOURCES += $$PWD/dmmu/dmmu.c \
$$PWD/qqtethenetmanager.cpp
} }
#customplot
SOURCES += $$PWD/customplot/qcpdocumentobject.cpp \
$$PWD/customplot/qcustomplot.cpp
HEADERS += $$PWD/customplot/qcpdocumentobject.h \
$$PWD/customplot/qcustomplot.h
#pluginwatcher
SOURCES += $$PWD/pluginwatcher/qdevicewatcher.cpp \
$$PWD/pluginwatcher/qqtpluginwatcher.cpp
HEADERS += $$PWD/pluginwatcher/qqtpluginwatcher.h \
$$PWD/pluginwatcher/qdevicewatcher.h \
$$PWD/pluginwatcher/qdevicewatcher_p.h
SOURCES += $$PWD/qqtcheckbox.cpp \ SOURCES += $$PWD/qqtcheckbox.cpp \
$$PWD/qqtdefine.cpp \ $$PWD/qqtdefine.cpp \
$$PWD/qqtdialog.cpp \ $$PWD/qqtdialog.cpp \
@ -124,11 +149,7 @@ SOURCES += $$PWD/qqtcheckbox.cpp \
$$PWD/qqtnetworkmessage.cpp \ $$PWD/qqtnetworkmessage.cpp \
$$PWD/qqtuserserialprotocol.cpp \ $$PWD/qqtuserserialprotocol.cpp \
$$PWD/qqtlanprotocol.cpp \ $$PWD/qqtlanprotocol.cpp \
$$PWD/qqtanimation.cpp \ $$PWD/qqtanimation.cpp
$$PWD/customplot/qcpdocumentobject.cpp \
$$PWD/customplot/qcustomplot.cpp \
$$PWD/pluginwatcher/qdevicewatcher.cpp \
$$PWD/pluginwatcher/qqtpluginwatcher.cpp
HEADERS += $$PWD/qqtcheckbox.h \ HEADERS += $$PWD/qqtcheckbox.h \
$$PWD/qqtdefine.h \ $$PWD/qqtdefine.h \
@ -177,11 +198,6 @@ HEADERS += $$PWD/qqtcheckbox.h \
$$PWD/qqtuserserialprotocol.h \ $$PWD/qqtuserserialprotocol.h \
$$PWD/qqtlanprotocol.h \ $$PWD/qqtlanprotocol.h \
$$PWD/qqtanimation.h \ $$PWD/qqtanimation.h \
$$PWD/customplot/qcpdocumentobject.h \
$$PWD/customplot/qcustomplot.h \
$$PWD/pluginwatcher/qqtpluginwatcher.h \
$$PWD/pluginwatcher/qdevicewatcher.h \
$$PWD/pluginwatcher/qdevicewatcher_p.h
FORMS += $$PWD/qqtcheckbox.ui \ FORMS += $$PWD/qqtcheckbox.ui \