#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QCompleter>
#include <QLineEdit>
#include <QStringList>
#include <QDebug>
#include <QTimer>

//#define NATIVE_WIDGETS

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QStringList wordList;
    wordList << "alpha" << "angle" << "omega" << "omicron" << "zeta";

    QCompleter *completer = new QCompleter(wordList, this);
    completer->setCaseSensitivity(Qt::CaseInsensitive);
    ui->lineEdit->setCompleter(completer);
    ui->lineEdit->setFocus();

    QMenu *menu = new QMenu(this);
    menu->addAction(tr("&First Item"));
    menu->addAction(tr("&Second Item"));
    menu->addAction(tr("&Third Item"));
    menu->addAction(tr("F&ourth Item"));
    ui->popupButton->setMenu(menu);

#ifdef NATIVE_WIDGETS
    setAttribute(Qt::WA_NativeWindow);
    ui->lineEdit->setAttribute(Qt::WA_NativeWindow);
#endif

#if QT_VERSION >= 0x50000
    setWindowTitle("Qt 5.0");
#else
    setWindowTitle("Qt 4.8");
#endif
    qApp->installEventFilter(this);

    QTimer timer(this);
    timer.singleShot(1000, this, SLOT(timeout()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::timeout()
{
    //ui->lineEdit->grabMouse();
}

bool MainWindow::eventFilter(QObject *o, QEvent *e)
{
    if (o->isWidgetType()) {
        switch (e->type()) {
        case QEvent::MouseButtonPress:
            break;
        case QEvent::MouseButtonRelease:
            break;
        case QEvent::MouseMove:
            break;
        case QEvent::Enter:
            qDebug() << "## Got Enter for:" << o;
            break;
        case QEvent::Leave:
            qDebug() << "## Got Leave for:" << o;
            break;
        default:
            break;
        }
    }
    return QMainWindow::eventFilter(o ,e);
}
