/*! \file crecherchewindow.cpp */ #include "crecherchewindow.h" #include "ui_crecherchewindow.h" #include "cimagewidget.h" #include "cmainwindow.h" #include "common.h" #include cRechercheWindow::cRechercheWindow(QWidget *parent) : cMDISubWindow(parent), ui(new Ui::cRechercheWindow), m_lpMainWindow((cMainWindow*)parent), m_lpRecherche(0) { ui->setupUi(this); ui->m_lpTab->setCurrentIndex(0); m_lpCharacterModel = new QStandardItemModel(0, 1); ui->m_lpCharacterList->setModel(m_lpCharacterModel); m_lpPlaceModel = new QStandardItemModel(0, 1); ui->m_lpPlaceList->setModel(m_lpPlaceModel); m_lpObjectModel = new QStandardItemModel(0, 1); ui->m_lpObjectList->setModel(m_lpObjectModel); connect(ui->m_lpCharacterList, &cTreeView::doubleClicked, this, &cRechercheWindow::onCharacterDoubleClicked); connect(ui->m_lpPlaceList, &cTreeView::doubleClicked, this, &cRechercheWindow::onPlaceDoubleClicked); connect(ui->m_lpObjectList, &cTreeView::doubleClicked, this, &cRechercheWindow::onObjectDoubleClicked); connect(ui->m_lpName, &cLineEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onLineEditGotFocus); connect(ui->m_lpName, &cLineEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onLineEditLostFocus); connect(ui->m_lpLink, &cLineEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onLineEditGotFocus); connect(ui->m_lpLink, &cLineEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onLineEditLostFocus); connect(ui->m_lpDescription, &cTextEdit::gotFocus, (cMainWindow*)parent, &cMainWindow::onTextEditGotFocus); connect(ui->m_lpDescription, &cTextEdit::lostFocus, (cMainWindow*)parent, &cMainWindow::onTextEditLostFocus); connect(ui->m_lpCharacterList, &cTreeView::gotFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewGotFocus); connect(ui->m_lpCharacterList, &cTreeView::lostFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewLostFocus); connect(ui->m_lpObjectList, &cTreeView::gotFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewGotFocus); connect(ui->m_lpObjectList, &cTreeView::lostFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewLostFocus); connect(ui->m_lpPlaceList, &cTreeView::gotFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewGotFocus); connect(ui->m_lpPlaceList, &cTreeView::lostFocus, (cMainWindow*)parent, &cMainWindow::onTreeViewLostFocus); } cRechercheWindow::~cRechercheWindow() { delete ui; } void cRechercheWindow::setRecherche(cRecherche* lpRecherche) { m_lpRecherche = lpRecherche; ui->m_lpName->setText(lpRecherche->name()); ui->m_lpLink->setText(lpRecherche->link()); ui->m_lpDescription->setDocument(lpRecherche->description()); QList images = lpRecherche->images(); for(int x = 0;x < images.count();x++) { cImage* lpImage = images[x]; QPixmap pixmap = lpImage->image(); cImageWidget* lpImageWidget = new cImageWidget; lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); } QSpacerItem* lpSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); ui->m_lpLayout->addItem(lpSpacer); QList characterList = lpRecherche->characterList(); QList placeList = lpRecherche->placeList(); QList objectList = lpRecherche->objectList(); QStringList headerLabels; headerLabels = QStringList() << tr("name") << tr("creature") << tr("gender") << tr("title"); m_lpCharacterModel->setHorizontalHeaderLabels(headerLabels); for(int x = 0;x < characterList.count();x++) { cCharacter* lpCharacter = characterList[x]; QList items; items.append(new QStandardItem(lpCharacter->name())); items.append(new QStandardItem(lpCharacter->creature())); items.append(new QStandardItem(lpCharacter->genderText())); items.append(new QStandardItem(lpCharacter->title())); if(lpCharacter->mainCharacter()) { QFont font = items[0]->font(); font.setBold(true); for(int y = 0;y < headerLabels.count();y++) items[y]->setFont(font); } for(int y = 0;y < headerLabels.count();y++) { items[y]->setData(QVariant::fromValue(lpCharacter)); items[y]->setToolTip(lpCharacter->description()->toPlainText()); } m_lpCharacterModel->appendRow(items); } ui->m_lpCharacterList->header()->setStretchLastSection(true); for(int i = 0;i < headerLabels.count();i++) ui->m_lpCharacterList->resizeColumnToContents(i); headerLabels = QStringList() << tr("name") << tr("location") << tr("type"); m_lpPlaceModel->setHorizontalHeaderLabels(headerLabels); for(int x = 0;x < placeList.count();x++) { cPlace* lpPlace = placeList[x]; QList items; items.append(new QStandardItem(lpPlace->name())); items.append(new QStandardItem(lpPlace->location())); items.append(new QStandardItem(lpPlace->type())); for(int y = 0;y < headerLabels.count();y++) { items[y]->setData(QVariant::fromValue(lpPlace)); items[y]->setToolTip(lpPlace->description()->toPlainText()); } m_lpPlaceModel->appendRow(items); } ui->m_lpPlaceList->header()->setStretchLastSection(true); for(int i = 0;i < headerLabels.count();i++) ui->m_lpPlaceList->resizeColumnToContents(i); headerLabels = QStringList() << tr("name") << tr("type"); m_lpObjectModel->setHorizontalHeaderLabels(headerLabels); for(int x = 0;x < objectList.count();x++) { cObject* lpObject = objectList[x]; QList items; items.append(new QStandardItem(lpObject->name())); items.append(new QStandardItem(lpObject->type())); for(int y = 0;y < headerLabels.count();y++) { items[y]->setData(QVariant::fromValue(lpObject)); items[y]->setToolTip(lpObject->description()->toPlainText()); } m_lpObjectModel->appendRow(items); } ui->m_lpObjectList->header()->setStretchLastSection(true); for(int i = 0;i < headerLabels.count();i++) ui->m_lpObjectList->resizeColumnToContents(i); setWindowTitle(tr("[recherche] - ") + lpRecherche->name()); connect(ui->m_lpName, &cLineEdit::textChanged, this, &cRechercheWindow::onNameChanged); connect(ui->m_lpLink, &cLineEdit::textChanged, this, &cRechercheWindow::onLinkChanged); connect(ui->m_lpDescription, &cTextEdit::textChanged, this, &cRechercheWindow::onDescriptionChanged); } cRecherche* cRechercheWindow::recherche() { return(m_lpRecherche); } void cRechercheWindow::onCharacterDoubleClicked(const QModelIndex& index) { QStandardItem* lpItem = m_lpCharacterModel->itemFromIndex(index); cCharacter* lpCharacter = qvariant_cast(lpItem->data()); if(lpCharacter) showCharacterWindow(lpCharacter); } void cRechercheWindow::onPlaceDoubleClicked(const QModelIndex& index) { QStandardItem* lpItem = m_lpPlaceModel->itemFromIndex(index); cPlace* lpPlace = qvariant_cast(lpItem->data()); if(lpPlace) showPlaceWindow(lpPlace); } void cRechercheWindow::onObjectDoubleClicked(const QModelIndex& index) { QStandardItem* lpItem = m_lpObjectModel->itemFromIndex(index); cObject* lpObject = qvariant_cast(lpItem->data()); if(lpObject) showObjectWindow(lpObject); } void cRechercheWindow::onNameChanged(const QString& szName) { m_lpRecherche->setName(szName); m_lpMainWindow->somethingChanged(); } void cRechercheWindow::onLinkChanged(const QString& szName) { m_lpRecherche->setLink(szName); m_lpMainWindow->somethingChanged(); } void cRechercheWindow::onDescriptionChanged() { m_lpMainWindow->somethingChanged(); }