void CommentDialog::on_button_smilely_clicked() { QSelectFaceWidget* selectFace = new QSelectFaceWidget(Global::emotionPathTemp, this); selectFace->setStyleSheet("QLabel{color: #000000}QPushButton{background-color: transparent}"); QPoint GlobalPoint(this->ui.button_smilely->mapToGlobal(QPoint(0, 0)));//获取控件在窗体中的坐标 int y = GlobalPoint.y(); selectFace->popUp(GlobalPoint, this->ui.button_smilely->height()+10); QObject::connect(selectFace, &QSelectFaceWidget::FaceSelected, [=](const QString &filename){ QString iconName = GetPicName(filename); QTextDocument *document =this->ui.TextEdit_commentText->document(); QTextCursor cursor = this->ui.TextEdit_commentText->textCursor(); QFileInfo fiPic(filename); if (fiPic.exists()) { QImage image(filename); image = image.scaled(30, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation); document->addResource(QTextDocument::ImageResource, QUrl(iconName), image); cursor.insertImage(iconName); } this->ui.TextEdit_commentText->setFocus(); //this->ui.TextEdit_commentText->moveCursor(QTextCursor::NoMove); }); };
//////////////////// // Helper function for TakeScreenshot static std::string GetScreenshotFileName(const std::string& scr_path, const std::string& extension) { std::string path = scr_path; // Append a slash if not present if (path[path.size() - 1] != '/' && path[path.size() - 1] != '\\') { path += '/'; } std::string filePrefix = GetDateTimeFilename(); filePrefix += "-"; if( tLX ) { if( tLX->iGameType == GME_LOCAL ) filePrefix += "local"; else if( tLX->iGameType == GME_HOST && cServer ) filePrefix += tLXOptions->sServerName; else if( cClient ) filePrefix += cClient->getServerName(); } // Make filename more fileststem-friendly if( filePrefix.size() > 64 ) filePrefix.resize(64); #define S_LETTER_UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define S_LETTER_LOWER "abcdefghijklmnopqrstuvwxyz" #define S_LETTER S_LETTER_UPPER S_LETTER_LOWER #define S_NUMBER "0123456789" #define S_SYMBOL ". -_&+" // No "\\" symbol, no tab. #define S_VALID_FILENAME S_LETTER_UPPER S_LETTER_LOWER S_NUMBER S_SYMBOL while( filePrefix.find_first_not_of(S_VALID_FILENAME) != std::string::npos ) filePrefix[ filePrefix.find_first_not_of(S_VALID_FILENAME) ] = '-'; static const size_t step = 256; // Step; after how many files we check if the filename still exists // We start at range from 1 to step size_t lower_bound = 0; size_t upper_bound = step; std::string fullname(path + GetPicName(filePrefix, upper_bound, extension)); // Find a raw range of where the screenshot filename could be // For example: between lierox1000.png and lierox1256.png while (IsFileAvailable(fullname, false)) { lower_bound = upper_bound; upper_bound += step; fullname = path + GetPicName(filePrefix, upper_bound, extension); } // First file? if (!IsFileAvailable(path + GetPicName(filePrefix, lower_bound, extension))) return path + GetPicName(filePrefix, lower_bound, extension); // Use binary search on the given range to find the exact file name size_t i = (lower_bound + upper_bound) / 2; while (true) { if (IsFileAvailable(path + GetPicName(filePrefix, i, extension), false)) { // If the current (i) filename exists, but the i+1 does not, we're done if (!IsFileAvailable(path + GetPicName(filePrefix, i + 1, extension))) return path + GetPicName(filePrefix, i + 1, extension); else { // The filename is somewhere in the interval (i, upper_bound) lower_bound = i; i = (lower_bound + upper_bound) / 2; } } else { // The filename is somewhere in the interval (lower_bound, i) upper_bound = i; i = (lower_bound + upper_bound) / 2; } } return ""; // Should not happen }