void LogViewerForm::provideContextMenu(const QPoint& p) { QTableWidgetItem* item = ui->tableWidget->itemAt(p); if (item != NULL && item->backgroundColor() == HighlightColor) { QAction* const action = mMenu->exec(mapToGlobal(p)); if (action != NULL) { bool ok = false; const int selected = ui->tableWidget->item(item->row(), 1)->text().toInt(&ok); Q_ASSERT(ok); const int generation = ui->tableWidget->item(item->row(), 2)->text().toInt(&ok); Q_ASSERT(ok); switch (action->data().toInt()) { case ShowPicture: emit showPicture(generation, selected); break; case CopyToClipboard: emit copyPicture(generation, selected); break; case GoToFolder: emit gotoPicture(generation, selected); break; default: #ifndef QT_NO_DEBUG qWarning() << "unknown command:" << action->data().toInt(); #endif break; } } } }
void SearchResultWidget::currentRowColumnChanged(int currentRow, int /*currentColumn*/, int previousRow, int /*previousColumn*/) { if (currentRow == previousRow) { return; } for (int col = 0; col < 3; ++col) { QTableWidgetItem* previousRowItem = searchTable->item(previousRow, col); QTableWidgetItem* currentRowItem = searchTable->item(currentRow, col); if (previousRowItem && col != 0) { QColor color = previousRowItem->data(Qt::UserRole + 15).value<QColor>(); if (color.isValid()) { previousRowItem->setBackgroundColor(color); } } if (currentRowItem) { QString text = currentRowItem->text(); if (col == 2 && !viewedItems.contains(text)) { viewedItems << text; } currentRowItem->setData(Qt::UserRole + 15, currentRowItem->backgroundColor()); currentRowItem->setBackgroundColor(QColor(Qt::green).lighter(170)); } } }
void MainWindow::recvStatusChanged(Status s) { QString str; str.sprintf("%d %d", s.first, s.second); ui->textEdit->append(str); QTableWidgetItem *item = ui->tableWidget->item(s.second,s.first); if(item){ QColor c = item->backgroundColor(); c.setRed(min(c.red() + 1,255)); item->setBackgroundColor(c); } }
void MainWindow::displayEvents(QDate debut, QDate fin) { this->current_debut = debut; this->current_fin = fin; QColor color(130,130,255); agenda_widget->clearContents(); if (this->em) { qDebug()<<"Mise à jour des events de la vue de la fenêtre principale"; vector<Evenement*> v = em->getFromPeriod(debut,fin); Evenement* ev; for (vector<Evenement*>::const_iterator it = v.begin(); it != v.end(); ++it) { color.setRgb(((color.red()+rand())%150)+106,((color.green()+rand())%150)+106,((color.blue()+rand())%150)+106); // que des couleurs claires ev = *it; int start_colonne = debut.daysTo(ev->getDateDebut()); int end_colonne = debut.daysTo(ev->getDateFin()); int start_ligne = ev->getHeureDebut().hour(); int end_ligne = ev->getHeureFin().hour()-1; int i = start_colonne>=0?start_colonne:0; int i_end = end_colonne<=6?end_colonne:agenda_widget->columnCount()-1; int j = start_colonne>=0?start_ligne:0; int j_end = end_colonne<=6?end_ligne:agenda_widget->rowCount()-1; int k = j; for (i;i<=i_end;i++) { for (k; k<agenda_widget->rowCount()&&(i!=i_end||k<=j_end); k++) { //qDebug()<<"i:"<<i<<"\t k:"<<k; QTableWidgetItem* item; if ((item = agenda_widget->item(k,i)) == nullptr) { agenda_widget->setItem(k,i, new QTableWidgetItem(ev->getTitre())); agenda_widget->item(k,i)->setBackgroundColor(color); //agenda_widget->item(k,i)->setFlags(agenda_widget->item(k,i)->flags() ^ Qt::ItemIsEditable); } else { item->setText(item->text()+" ; "+ev->getTitre()); QColor tmp = item->backgroundColor(); tmp.setRgb((tmp.red()+color.red())/2,(tmp.green()+color.green())/2,(tmp.blue()+color.blue())/2); item->setBackgroundColor(tmp); } } k = 0; } } } }
void SpreadSheet::selectColor() { QTableWidgetItem *item = table->currentItem(); QColor col = item ? item->backgroundColor() : table->palette().base().color(); col = QColorDialog::getColor(col, this); if (!col.isValid()) return; QList<QTableWidgetItem*> selected = table->selectedItems(); if (selected.count() == 0) return; foreach(QTableWidgetItem *i, selected) if (i) i->setBackgroundColor(col); updateColor(table->currentItem()); }
//----------------------------------------------------------------------------- void ChannelSelectionDialog::on_channel_table__cellClicked (int row, int column) { QTableWidgetItem* item = ui_.channel_table_->item (row, column); if (column == LABEL_INDEX_) { self_setting_ = true; if (item->checkState() == Qt::Checked) item->setCheckState (Qt::Unchecked); else item->setCheckState (Qt::Checked); } else if (column == COLOR_INDEX_) { QColorDialog color_dialog (item->backgroundColor (), this); if (color_dialog.exec () == QDialog::Accepted) updateColor (row, color_dialog.selectedColor ()); } self_setting_ = false; }