void Dialog::createWidget() { createdWidgetx = true; dgReadByUser = false; int w = smiles->size().width() / W_CNT; int h = smiles->size().height() / H_CNT; lwHistory = new QListWidget(); teMessage = new TextEditMessage(); //teHistory->setReadOnly(true); addWidget(lwHistory); setStretchFactor(0, 2); panel = new QToolBar(); QIcon newIcon = QPixmap::fromImage(smiles->copy(w, 0, w, h)); QAction *a = new QAction(newIcon, QString("&Smiles"), 0); a->setPriority(QAction::LowPriority); a->setShortcut(Qt::CTRL + Qt::Key_S); connect(a, SIGNAL(triggered()), this, SLOT(slotClickedSmileMenu())); panel->addAction(a); panel->setFixedHeight(30); //panel->pos() /*QMenuBar *panel = new QMenuBar(this); panel->setFixedHeight(30); panel->setAutoFillBackground(true); panel->setStyleSheet("QMenuBar { background-color: #f3f2f1; } QMenuBar::item { background-color: #f3f2f1; }"); //panel->setStyleSheet("QMenuBar::item { icon-size: 32px; } "); //panel->setStyleSheet("QMenuBar::button { background-color: #ffffff; }");*/ addWidget(panel); addWidget(teMessage); smileMenu = new QMenu("Smiles"); smileMenu->setIcon(QPixmap::fromImage(smiles->copy(w, 0, w, h))); smileMenu->setStyleSheet("QMenu { background-color: #ffffff;}"); QGridLayout *lytSmiles = new QGridLayout(smileMenu); QPalette palw; palw.setBrush(smileMenu->backgroundRole(), Qt::white); smileMenu->setAutoFillBackground(true); smileMenu->setPalette(palw); for (int i = 0; i < W_CNT; ++i) for (int j = 0; j < H_CNT; ++j) { QImage icon = smiles->copy(j * w, i * h, w, h); SmileButton *but = new SmileButton(icon, W_CNT * i + j); connect(but, SIGNAL(clicked()), this, SLOT(slotSmilesClicked())); lytSmiles->addWidget(but, i, j); //teMessage->document()->addResource(QTextDocument::ImageResource, QUrl(but->name()), smiles->copy(j * w, i * h, w, h)); //teHistory->document()->addResource(QTextDocument::ImageResource, QUrl(but->name()), smiles->copy(j * w, i * h, w, h)); } reloadResource(message()); smileMenu->setFixedSize(lytSmiles->sizeHint()); lwHistory->scrollToBottom(); connect(&tmrNotActive, SIGNAL(timeout()), this, SLOT(slotNotActiveBehav())); connect(teMessage, SIGNAL(gotFocus()), this, SLOT(slotFinishReadMessage())); connect(teMessage, SIGNAL(lostFocus()), this, SLOT(slotNotActiveBehav())); }
void Dialog::appendToHistory(const QString& name, const QDateTime& sendTime, QTextDocument *document, InsertingMode mode) { QListWidgetItem *item = new QListWidgetItem(); QTextEdit *te = new QTextEdit(); lwHistory->addItem(item); te->setReadOnly(true); reloadResource(te); lwHistory->setItemWidget(item, te); QString color; if (name == "You") color = "blue"; else color = "red"; te->append(QString("<font color = \"%1\"> <b>" + name + "</b> (" + sendTime.toString("dd-MM-yyyy hh:mm:ss") + "):</font>").arg(color)); te->moveCursor(QTextCursor::End); te->textCursor().insertBlock(); te->textCursor().insertFragment(QTextDocumentFragment(document)); int heig = 17, widthTe = parentWidget()->width(); int curLine = 0; int mx = 0; for (QTextBlock bl = te->document()->begin(); bl != te->document()->end(); bl = bl.next()) if (bl.isValid()) { if (bl.begin().atEnd()) { heig += 17 + mx;//&&& curLine = mx = 0; continue; } for (QTextBlock::iterator it = bl.begin(); !it.atEnd(); ++it) { QTextFragment fragm = it.fragment(); int curw, curh; if (fragm.isValid() && fragm.charFormat().isImageFormat()) { curw = smiles->width() / W_CNT; curh = smiles->height() / H_CNT; processCalc(heig, mx, curLine, curw, curh); } else if (fragm.isValid()) { QString s = fragm.text(); QFontMetrics me(fragm.charFormat().font()); curh = me.lineSpacing(); for (int j = 0; j < s.size(); ++j) { curw = me.width(s[j]); processCalc(heig, mx, curLine, curw, curh); } } } heig += mx; mx = curLine = 0; } te->setStyleSheet(QString("QFrame {" "border: 2px solid #f3f2f1;" "border-radius: 4px;" "padding: 2px;}")); item->setSizeHint(QSize(0, heig + 18)); te->resize(QSize(widthTe, heig)); lwHistory->scrollToBottom(); if (mode == ReceivedMessage && !dgReadByUser) { setUnreadMessage(unreadMessage + 1); queUnreadWrote.push_back(te); te->setStyleSheet("QTextEdit { background-color: #FFFCCC; }"); } else if (mode == LoadHistory) { if (unreadMessage != 0) { queUnreadWrote.push_back(te); te->setStyleSheet("QTextEdit { background-color: #FFFCCC; }"); if (queUnreadWrote.size() > unreadMessage) { queUnreadWrote.front()->setStyleSheet("QTextEdit { background-color: #FFFFFF; }"); queUnreadWrote.pop_front(); } } if (wroteMessage != 0) { queUnreadWrote.push_back(te); te->setStyleSheet("QTextEdit { background-color: #DFFFCC; }"); if (queUnreadWrote.size() > wroteMessage) { queUnreadWrote.front()->setStyleSheet("QTextEdit { background-color: #FFFFFF; }"); queUnreadWrote.pop_front(); } } } else if (mode == SendMessage) { teMessage->setFocus(); te->setStyleSheet("QTextEdit { background-color: #DFFFCC; }"); wroteMessage++; queUnreadWrote.push_back(te); } }
void ResourceManager::notifiedFileChanged( const Torque::Path &path ) { reloadResource( path, true ); }