Post::Post(QWidget *parent): QWidget(parent) { setFixedSize(parent->minimumWidth(),25); setObjectName("Post"); manager=new QNetworkAccessManager(this); Config::setManager(manager); auto layout=new QHBoxLayout(this); layout->setMargin(0); layout->setSpacing(0); commentM=new QComboBox(this); commentM->addItems({tr("Top"),tr("Slide"),tr("Bottom")}); commentM->setCurrentIndex(1); commentM->setFixedWidth(commentM->sizeHint().width()); layout->addWidget(commentM); commentC=new QPushButton(this); commentC->setFixedWidth(25); setColor(Qt::white); connect(commentC,&QPushButton::clicked,[this](){ QColor color=QColorDialog::getColor(getColor(),lApp->mainWidget()); if(color.isValid()){ setColor(color); } }); layout->addWidget(commentC); commentL=new QLineEdit(this); commentL->setFocus(); layout->addWidget(commentL); commentS=new QComboBox(this); layout->addWidget(commentS); commentB=new QPushButton(tr("Post"),this); commentB->setDefault(true); commentB->setFixedWidth(55); commentB->setToolTip(tr("DA☆ZE!")); layout->addWidget(commentB); commentA=new QAction(this); commentA->setShortcut(QKeySequence("Ctrl+Enter")); connect(commentB,&QPushButton::clicked,commentA,&QAction::trigger); connect(commentL,&QLineEdit::returnPressed,commentA,&QAction::trigger); connect(commentA,&QAction::triggered,[this](){ if(!commentL->text().isEmpty()){ postComment(); commentL->clear(); hide(); } }); connect(Danmaku::instance(),&Danmaku::modelReset,[this](){ commentS->clear(); int w=0; for(const Record *r:getRecords()){ commentS->addItem(r->string,(quintptr)r); w=qMax(w,commentS->fontMetrics().width(r->string)); } commentS->setVisible(commentS->count()>=2); commentS->setFixedWidth(w+30); }); hide(); }
void ScrapbookUI::viewBlog(int index) { erase(); bool isBlog = checkType(index); if( !isBlog){ endwin(); return; } bool commenting = true; int offset=0; int row = 2; int max, displayNumber=7; while(commenting){ std::vector<Post*> wholeScrapbook = scrapbook->getAllPosts(); erase(); refresh(); Blog* currentBlog; currentBlog = (Blog*) wholeScrapbook[index]; QString *currentContent = new QString(currentBlog->getContent()); std::vector<Comment*> allComments = currentBlog->getAllComments(); erase(); endwin(); erase(); mvprintw(0, 0, "Press up or down to scroll or Enter to post comment."); mvprintw(2,0, "Blog Title: "); printw(currentBlog->getTitle().toStdString().c_str()); mvprintw(3,0, "Content: "); printw(currentContent->toStdString().c_str()); mvprintw(12, 0, "Comments:"); refresh(); row=13; if(allComments.size() < displayNumber) max = allComments.size(); else max = offset+displayNumber; for(int i=offset;i<max;i++){ Comment *currentComment = allComments.at(i); QString currentContent = currentComment->getAuthorUsername() + ": " + currentComment->getContent(); mvprintw(row, 0, currentContent.toStdString().c_str()); refresh(); row++; } int ch= getch(); if(ch==KEY_DOWN && !((allComments.size())==(max))) offset++; else if(ch==KEY_UP && offset>0) offset--; else if(ch==KEY_UP); else if(ch==KEY_DOWN); else if(ch==10){//enter key postComment(index); if(allComments.size() > displayNumber) offset=allComments.size()-displayNumber - 1; } else commenting=false; } }